Control Names and InStr

On a continuous form that sorts columns when user clicks the column headers. 
I also have some embedded gif icons next to each column header caption that 
display ascending and descending order and named them with the convention of 
icon_up_TheControlName and icon_down_TheControlName. I also have an embedded 
gif icon called "cmdRemove" on the form.

If I run my sub in the "USAGE" section below, my sub FlipSortImages iterates 
through the form and correctly changes the icon_up_firstName control visible 
property to true and sets all of the other control's visible property to 
false. The problem is that I can't seem to exclude the "cmdRemove" icon from 
being affected.

In my code I have a simple message box that should fire when the sub reaches 
the "cmdRemove" icon, but it won't recognize it. Can someone setup a simple 
test form with a few controls using my naming convention and help me find a 
conditional test that will exclude any image controls that have the 
"cmdRemove" name or for that matter, any image control name that begins with 
"cmd"?

I also tried using the InStr() function to no avail.



'USAGE *******************

    Call FlipSortImages(Me.icon_up_firstName)



'EXAMPLE IMAGE CONTROL NAMES *******************

icon_up_firstName
icon_down_firstName
icon_up_lastName
icon_down_lastName
cmdRemove


'CODE ************************************

Sub FlipSortImages(ctlImageHot As Control)

     Dim ctl As Control

     For Each ctl In Me.Controls

        If ctl.ControlType = acImage Then
            If InStr(ctlImageHot.Name, "icon_up_") > 0 Or 
InStr(ctlImageHot.Name, "icon_down_") > 0 Then
                If ctl.Name <> ctlImageHot.Name Then
                    If ctl.Name = "cmdRemove" Then ' this is the part
                        MsgBox ctl.Name
                    Else
                        ctl.Visible = False
                    End If
                Else
                    ctl.Visible = True
                End If
            End If
        End If


     Next ctl

End Sub 


0
scott
4/10/2007 4:24:34 PM
access.formscoding 7493 articles. 0 followers. Follow

2 Replies
545 Views

Similar Articles

[PageSpeed] 16

On Tue, 10 Apr 2007 11:24:34 -0500, "scott" <sbailey@mileslumber.com> =
wrote:

>On a continuous form that sorts columns when user clicks the column =
headers.=20
>I also have some embedded gif icons next to each column header caption =
that=20
>display ascending and descending order and named them with the =
convention of=20
>icon_up_TheControlName and icon_down_TheControlName. I also have an =
embedded=20
>gif icon called "cmdRemove" on the form.
>
>If I run my sub in the "USAGE" section below, my sub FlipSortImages =
iterates=20
>through the form and correctly changes the icon_up_firstName control =
visible=20
>property to true and sets all of the other control's visible property to=
=20
>false. The problem is that I can't seem to exclude the "cmdRemove" icon =
from=20
>being affected.
>
>In my code I have a simple message box that should fire when the sub =
reaches=20
>the "cmdRemove" icon, but it won't recognize it. Can someone setup a =
simple=20
>test form with a few controls using my naming convention and help me =
find a=20
>conditional test that will exclude any image controls that have the=20
>"cmdRemove" name or for that matter, any image control name that begins =
with=20
>"cmd"?
>
>I also tried using the InStr() function to no avail.
>
>
>
>'USAGE *******************
>
>    Call FlipSortImages(Me.icon_up_firstName)
>
>
>
>'EXAMPLE IMAGE CONTROL NAMES *******************
>
>icon_up_firstName
>icon_down_firstName
>icon_up_lastName
>icon_down_lastName
>cmdRemove
>
>
>'CODE ************************************
>
>Sub FlipSortImages(ctlImageHot As Control)
>
>     Dim ctl As Control
>
>     For Each ctl In Me.Controls
>
>        If ctl.ControlType =3D acImage Then
>            If InStr(ctlImageHot.Name, "icon_up_") > 0 Or=20
>InStr(ctlImageHot.Name, "icon_down_") > 0 Then
>                If ctl.Name <> ctlImageHot.Name Then
>                    If ctl.Name =3D "cmdRemove" Then ' this is the part
>                        MsgBox ctl.Name
>                    Else
>                        ctl.Visible =3D False
>                    End If
>                Else
>                    ctl.Visible =3D True
>                End If
>            End If
>        End If
>
>
>     Next ctl
>
>End Sub=20
>

As an additional debugging help, I would suggest either moving the MsgBox
statement up to immediately after the first "If" statement, or else using
Debug.Print to print all of the control names to the immediate window in =
VBA
view.

Surprisingly often in situations such as this, the control you are =
concentrating
on actually has a name like "Command23" or "Text24" instead of what you =
think it
has. The above procedure should help eliminate that possibility; at least=
 it has
helped me on numerous occasions! :)

--
Bob Hairgrove
NoSpamPlease@Home.com
0
Bob
4/10/2007 5:54:42 PM
thanks, i fixed it.

"Bob Hairgrove" <invalid@bigfoot.com> wrote in message 
news:0hjn13p0mqhirmvnfsivbk5kl5mkl0bkrh@4ax.com...
On Tue, 10 Apr 2007 11:24:34 -0500, "scott" <sbailey@mileslumber.com> wrote:

>On a continuous form that sorts columns when user clicks the column 
>headers.
>I also have some embedded gif icons next to each column header caption that
>display ascending and descending order and named them with the convention 
>of
>icon_up_TheControlName and icon_down_TheControlName. I also have an 
>embedded
>gif icon called "cmdRemove" on the form.
>
>If I run my sub in the "USAGE" section below, my sub FlipSortImages 
>iterates
>through the form and correctly changes the icon_up_firstName control 
>visible
>property to true and sets all of the other control's visible property to
>false. The problem is that I can't seem to exclude the "cmdRemove" icon 
>from
>being affected.
>
>In my code I have a simple message box that should fire when the sub 
>reaches
>the "cmdRemove" icon, but it won't recognize it. Can someone setup a simple
>test form with a few controls using my naming convention and help me find a
>conditional test that will exclude any image controls that have the
>"cmdRemove" name or for that matter, any image control name that begins 
>with
>"cmd"?
>
>I also tried using the InStr() function to no avail.
>
>
>
>'USAGE *******************
>
>    Call FlipSortImages(Me.icon_up_firstName)
>
>
>
>'EXAMPLE IMAGE CONTROL NAMES *******************
>
>icon_up_firstName
>icon_down_firstName
>icon_up_lastName
>icon_down_lastName
>cmdRemove
>
>
>'CODE ************************************
>
>Sub FlipSortImages(ctlImageHot As Control)
>
>     Dim ctl As Control
>
>     For Each ctl In Me.Controls
>
>        If ctl.ControlType = acImage Then
>            If InStr(ctlImageHot.Name, "icon_up_") > 0 Or
>InStr(ctlImageHot.Name, "icon_down_") > 0 Then
>                If ctl.Name <> ctlImageHot.Name Then
>                    If ctl.Name = "cmdRemove" Then ' this is the part
>                        MsgBox ctl.Name
>                    Else
>                        ctl.Visible = False
>                    End If
>                Else
>                    ctl.Visible = True
>                End If
>            End If
>        End If
>
>
>     Next ctl
>
>End Sub
>

As an additional debugging help, I would suggest either moving the MsgBox
statement up to immediately after the first "If" statement, or else using
Debug.Print to print all of the control names to the immediate window in VBA
view.

Surprisingly often in situations such as this, the control you are 
concentrating
on actually has a name like "Command23" or "Text24" instead of what you 
think it
has. The above procedure should help eliminate that possibility; at least it 
has
helped me on numerous occasions! :)

--
Bob Hairgrove
NoSpamPlease@Home.com 


0
scott
4/10/2007 6:04:35 PM
Reply:

Similar Artilces:

Control Access to groups of contacts
I have a client who wants to have a master contact list so he can see the entire list. He has a handful of clients who will need to be able to view overlapping subsets of those contacts, but should not be able to view the entire list. Can access control be applied at this granularity? User Attributes or other Security groups are acceptible components of this access control. For instance, UserA needs to see contacts 1, 3 and 5 UserB needs to see contacts 1, 2, and 3 UserC needs to see contacts 2, 4, and 5 UserD needs to see contacts 1, 3, 4, and 5 ...

OnEvent Click and Tab Controls
Good Day All.. I have an issue that I had posted previously but it did not get resolved. It may partially be my fault for not explaining my need/question correctly. I have a form. The form contains a subform. & a tab control. The subform has 3 fields listed for the user: ShipTo, BillTo & Account Name The tab control has 3 tabs. The first tab is where I am struggling right now. I want the user to select ('click') on the "account" in the subform (data sheet) at the top. Once they click the "account" the fields on the tab control will then fill wit...

Count File Names
Hi All, I having an issue with version control on Buisness cases. I currently have a spreadsheet that looks into a folder and picks up details from a number of files. However, they require version control numbers so there will eventually be multiple files say 2010-01 v1.0, 2010-01 v1.1. Is there a way I can: 1) Get a macro to count the number of 2010-01 files there are in the folder, and 2) Get my version control sheet to look at the latest version of the file (in this example: 2010-01 v1.1) Cheers, Chris See if this code works. I assume that 2010-01 is year and month. ...

>> Calendar Control drag to select range
Hi, using MS Access 2003, is it possible to allow a user to drag to select a range of dates and, if 'yes', how do you store the selected date range? Many thanks, Jonathan Not that I know of. Storing a range of dates is quite simple though. You store the start date and the end date and use a calculation to show all the dates between. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Jonathan" <Jonathan@discussions.microsoft.com> wrote in message news:4F22299F-3765-40D2-AA03-67FB42FFC07A@microsoft.com... > ...

How do I find the location of the font control in Win XP
Hi All, I'd like to change my fonts every now and then but don't know where to find them. Could someone please tell me where they are an how to use them? Thanks, Don Don, This newsgroup deals with Microsoft Access, a relational database application. You'll have better luck posting this on a newsgroup related to Windows Fonts. Try... microsoft.public.word.printingfonts -- hth Al Campagna Microsoft Access MVP http://home.comcast.net/~cccsolutions/index.html "Find a job that you love... and you'll never work...

Name prefixing in reply message
All, I'm not even sure what terms to google for related to this problem. If you get an email from someone in the Office XP version of Outlook, and you click reply to that email, then start typing inside the portion of the message that contains the original message you replied to, it will automatically prefix everything you write with your name. How does one turn this off? Thanks in advance! TwistedPair wrote: > I'm not even sure what terms to google for related to this problem. If you > get an email from someone in the Office XP version of Outlook, > and you click...

naming a worksheet
i want to control how the sheets are named, for instance how do i ensur that when i click on Insert Worksheet i will get a worksheet with le us say the name 'Prapti' instead of Sheet1,Sheet2 etc. Also can i change the last nos of the sheet, for instance if i creat Sheet3 and then delete it , the next sheet is created with the no Sheet4 and not Sheet3, how can i change tha -- Message posted from http://www.ExcelForum.com Try something like: Sub NameNewSheet() Dim sName As String Dim wTemp As Worksheet Sheets.Add.Name = "wTemp" sName = InputBox("Name of new s...

Cview and Tree control
I have an MDI application which renders opengl scenes in a document. The CView class continously calls opengl library and paints the scene. Here is a screenshot: http://limefocus.net/screenshot.jpg I would like to add a tree control inside the document to manupilate the image generated in the CView. Is it possible to embed a tree control in a CDocument? Thanks. Jess You are mixing the paradigms here. A document does not care how its data is represented. Question you shoud ask is if you can put a tree control in your view. The answer is : absolutely. You can use a splitter to put a t...

View names
Is it possible to give the same name to two different views when the views are for different entities? For instance, name a view for Leads "Has email" and name a view for Accounts "Has email." I seem to be running into a bug when doing this. I receive the following error: User would see... "Duplicate Record The specified domain logon name already exists. You must specify a unique domain logon name or open the user record that is using this name already." However, I'm not changing a domain logon name. I am changing the name of a view. Any ideas? I'v...

Control Button
Hello I need some help with a form. What I am trying to do is, to place a button on a form in MS Access so that when you click on it, in another field it will display a number one. If you click on the same button again it will change the one to a two and so on. Wes Private Sub YourCommandButton_Click() YourTextBox = YourTextBox + 1 End Sub -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200705/1 "Wes Derhak" <derhak.wg@shaw.ca&...

Different display names
Hi Is there any way to have an account display differently in the FROM field compared to the GAL (Exchange 2003). We would like the user to appear in the GAL as "Bob User" but when an external recipient reads an email it should be displayed as "Bob of Company <bob.user@company.com>". Cheers Stuart ...

File name from a cell
I am trying to have date in a cell become the file name and appear i the save as dialog box as the file is saved the first time -- Message posted from http://www.ExcelForum.com One way: Option Explicit Sub testme01() Dim mySuggestedFileName As String Dim myFileName As Variant With Worksheets("sheet1") mySuggestedFileName = "c:\my documents\excel\test\" _ & Format(.Range("a1").Value, "yyyy_mm_dd") & ".xls" End With myFileName = Application.GetSaveAsFilename _ ...

M2004: Change name on home page?
I'm using Money 2004. On the home page it says "So-and-so's Money Home Page". How can I change the name that appears there? -Rod > I'm using Money 2004. On the home page it says "So-and-so's Money Home > Page". How can I change the name that appears there? Figures... I always seem to find a solution right after posting a question! Click Accounts & Bills, Account Setup, Update Personal Information. -Rod ...

How do you control the color/pattern of a pie chart?
I need help with my pie charts. I need to create pie charts that are easily understood in B&W. How do I set the color or pattern for each portion of my pie chart? Hi, To format a slice you need to select it first. Click the pie once to select all slices. Click again to select individual slice. You can use the Fill Effects > Patterns to fill with b/w patterns. Also in print preview the Setup dialog has a Print Black & White option on the Chart Tab. Note this is only visible if you have a chart sheet or select the chartobject before print preview. If you are printing chartobje...

Unlocking named ranges
I am working with a spreadsheet created by a former employee. He used named ranges a lot. I am trying to understand the worksheet. When I see an equation in a cell like =Sum(Shipments) I feel I know what it means. But how do I learn what the actual cell reference is ie = Sum(D2:G2).? TIA Insert a new, empty worksheet into the workbook. Then you can use The Insert-> Name-> Paste menu option and click on the Paste List button to get a listing of all the names and the definitions "JohnL" wrote: > I am working with a spreadsheet created by a former employee. He used...

Linked Spreadsheets Grandfather Name Sticking
Hello, Here's an example of the problem. Let's say I have a store that sells gasoline. I want to record my store sales, and gasoline sales in gallons. So, I have a spreadsheet for store sales and a spreadsheet for gas sales in gallons. And these are setup per month. January sales sheets, February sales sheets, etc. I have the gas gallons spreadsheet linked to the stores sales spreadsheet, so I can enter all the data while in the sales spreadsheet. Let's say I have entered all of January's sales and gas data and want to move on to February's data. I copy Jansale...

reading file name from folder function
I am using Access 97. Just wonder if there is a fuction which can read all the file name from a folder and put it to a column in a table. Please let me know. Thanks. Hi. >I am using Access 97. Just wonder if there is a fuction which can read all >the file name from a folder and put it to a column in a table. Please see the getFileInfo( ) function in the tip, "How to compare the contents of two directories," on the following Web page for an example: http://www.access.qbuilt.com/html/vba1.html HTH. Gunny See http://www.QBuilt.com for all your database needs. See http...

Printer Control
I have a printer control on my form and when I use it, it prints to the default printer. I would like for it to bring up the screen to allow me to select which printer to use, like when you use the file/print way. thanks Blair Private Sub Command310_Click() On Error GoTo Err_Command310_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.PrintOut acSelection DoCmd.GoToControl "CloseFemaleCards" Exit_Command310_Click: Exit Sub Err_Command310_Click: MsgBox Err.Description Resume Exit_Command310_Click End Sub This will call the print...

ActiveX control being added to outgoing e-mail?
I have a user running Outlook 2003 via Exchange 2000. All outgoing messages sent by his system apparently have an ActiveX control in them. Any messages I try to open on another machine give the alert "Your current Security settings prohibit running ActiveX controls..." Could this mean the user has a virus? Something else? Any help is appreciated, and a direct reply to me is appreciated as well. Thanks, John M John discovered this was due to bad signature or stationary files in Outlook. I had the same problem with a user and tested this theory. There was indeed some c...

Named Ranges
Hi! I created several worksheets that contained huge lists, so I created a dynamic named range. Now that the name has been inserted in my array formulas, my Macro runs very slowly. The Macro unprotects one of my sheets, sorts the data in a table, hides the blank rows and the protects the sheet again. There are no related named range formulas in that worksheet, so I'm not sure why it would be affected. The Macro ran quickly when I had a defined range of data. Would giving a named range like 'Date' and having text in my workbook with 'Date' create conflicts? Could this...

Report names in listbox
I recently upgraded to Access 2007 and am having some trouble with the changes. I have a form with a listbox in which I would like to display the names of all the reports in the database. I've tried using the following as the rowsource for the listbox, but in form view nothing is displayed. Does anyone know how to do this? TIA, Ken Warthen kenwarthen@gmail.com "SELECT MSysObjects.Name FROM MSysObjects WHERE (((Left([Name],1))<"~") AND ((MSysObjects.Type)=-32764)) ORDER BY MSysObjects.Name;" I think you made a slight typo. Try (((Left([Name],1))<>&quo...

Send Emails With A Different Name Than How Its Listed in the GAL
Hi all, I have a quick question: My client is unhappy with how his emails get sent out from MS Outlook. The GAL on our server lists names as [Last Name], [First Name]. This is how the majority of our clients want it. However, he wants his to be [First Name] [Last Name]. So, all recipients getting emails from him will see his name as First Name, Last Name. We can't do this for him on our GAL, since it would obviously cause an inconsistency if we did it only for one name. But, I figured I'd post here to see if anything else can be done to accomodate him. Thanks in advance for your help...

Problem with multiline tab control #2
Hi, I have a problem with a tab control that I just can't seem to figure out. I have a tab control that made multi-line capable with m_ctrlTab.ModifyStyle(TCS_MULTILINE,TCS_MULTILINE); but, ever since I made the change I can't seem to display whichever tab I want upon application startup. It used to be a regular single-line tab (with 5 tabs) but I'm running out of space which is why I need a multiline solution. I have 6 tabs right now, three in one row. My code looks like this: ------------------------------- snip ------------------------------- BOOL Cxxxx:OnInitDialog() { ...

Switching Names Around
Hey gurus- I am getting a list of names imported into Excel. All the names are in the order of LAST NAME FIRST MI/[SPOUSE] FIRST [SPOUSE] MI. All of them have their last name at the beginning, and they're all merged into the same cell. I am trying to print out mailers, so I need the 1st name moved to the back of the line so it prints out normally. How would I write a macro to do this? The only way I can think of is to signal is off the very 1st SPACE- everything before that space gets added to the end of the line. Is this possible to do? How do I do this? I'm not very good at VB, so...

Upper Control Limits
I have a line chart that shows 12 months of data and a trend line. I computed the Upper & Lower Control Limits using the Standard Deviation. Is there a way to put these lines on my charts so that when my boss looks at it she can tell if one or more of the points are out of control? Thanks In Advance Wm. William: This link will show you how to build a control chart in Excel. http://processtrends.com/pg_charts_control_chart.htm ....Kelly koday@processtrends.com "williamr" <williamr@discussions.microsoft.com> wrote in message news:64B0E55A-F4F1-4FE9-9566-C9BCCF2...