Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to Contents of Menu Item Tag

Status
Not open for further replies.

StumblingThrough

Technical User
Nov 7, 2002
88
US
Can anyone tell me how to refer to the contents of the tag of menu item control using VBA?
 
menu bars do not have a tag property that I know of.
 
Maybe I'm using the wrong name. It's a custom command item beneath a toolbar menu item. Does this help?
 
Well, this was in the Access Help. Not sure if will work for what you are doing:

This example finds the first control with the tag value "Change this bar." If the control with that tag value is a command bar button, the example adds a new combo box control to the end of the command bar and changes the tag value of the found button to "Changed."

Set ctrl = CommandBars _
.FindControl(Tag:="Change this bar")
If ctrl Is Nothing Then Goto notFound
If ctrl.Type = msoControlButton Then
Set br = ctrl.Parent
br.Controls.Add(Type:=msoControlComboBox)
ctrl.Tag = "Changed"
End If
 
Partially. I do believe the answer has something to do with the CommandBar property. I did see the above in Access help, but doesn't really help much. I'm not trying to find a control with a specific tag. I'm trying to determine the tag of the current contol within the menubar.
 
If you look at the last line it shows ctl.tag. That would be how you get that tag. If you are making changes to it, it might be something like this:

ctl.tag = "abcde
 
Boy, this is still confusing, and is apparently way beyond my level of understanding. I'm trying to run code based on the contents of the tag. I just can't get the structure correct on referring to the name of the tag.

Dim str as string
str = CommandBars("CommandBarName").Control().tag

Select Case str
Case "Joe"
Run This Code....
Case "Larry"
Run That Code....
Case Else
Just Run...
End Select
 
ok. You are trying to assign an object to a string variable. Here is what you should do. I hope this is what you are looking for:

Private Sub Command5_Click()
Dim ctrl As Access.Application
Set ctrl = New Access.Application

ctrl.CommandBars.Item("Utility 1").Controls.Item(1).Tag = "Joe"

Select Case ctrl.CommandBars.Item("Utility 1").Controls.Item(1).Tag
Case "Joe"
MsgBox "Options"
'Run This Code....
Case "Larry"
'Run That Code....
Case Else
'Just Run...
End Select
End Sub
 
hneal98,

Thanks. I will give it a try. I assumed the contents of the TAG was a string. What I was trying to do was assign the contents of the tag to a variable, and then run code based on that variable (or contents of the tag).

What I don't understand in your code (below) is why you are assigning the tag to the name "Joe".

ctrl.CommandBars.Item("Utility 1").Controls.Item(1).Tag = "Joe"

I don't want to assign the tag a specific name - I want to know what the contents of the tag is. I assume your code above will do that, and I just fail to see how it works.
 
That portion was just for my example where I assinged it a name so it would have something to look for. I used one of the names you had in your example. You will note that I put in a message box where in the portion of the select case where Joe was to be found.

The tag will have no information unless you assign something there. It is only a space holder.
 
Thanks, but that didn't work. Here is what I was trying to accomplish.

I've got three different menu items. I've also got three different forms. When one of the menu items is selected, I want to open one of the form. Instead of having 3 different functions which vary only by the form name, I was trying to use the same function for all three. I was trying to place the form name in the menu item's tag, and have the function open the form that corresponds to the tag. Then tag contents will NEVER change - I set that value during programming.

In any case, this is probably not worth the aggrivation. I'll just go with three different functions.

Thanks anyway!
 
Not sure why you wanted to use the tag. All you needed to do is store the form name in a variable and change the peice of code that actually opens the form.
 
Example: Here are my Menu Items.

View > Open Form1
View > Open Form2
View > Open Form3

When the user selects View > Open Form1, I want to programatically open the form named Income. ...Open Form2 would open a form named Contacts, etc. I was going to store the names Income and Contacts in the appropriate menu item's tag. The function (OpenForm) called by each menu item would then assign a variable (Tagcontents) to the contents of the tag, and perform an

Function OpenForm()
TagContents = (Whatever code is that can get this piece of info)
DoCmd.OpenForm "Tagcontents".
End Function

Can you suggest a better way?
 
sub OpenForm(FormName as Form)
TagContents = (Whatever code is that can get this piece of info)
DoCmd.OpenForm FormName.
End sub

Then wherever you have your function call, it would look like this, actually, note that I changed it to a sub. You are not returning anything, just opening a form:

OpenForm Forms!WhatEverTheNameOfYourFormIs

where WhatEverTheNameOfYourFormIs is replaced by the actual name of your form.

And that is all there is to it. Let me know if you still have problems with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top