How to get the properties of Menu Control?

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 21:43
Joined
Mar 22, 2009
Messages
1,008
How to read the properties of a menu control programatically. Suppose I having a Menu named "Reports" and "Activities","Process" as controls under that menu. How to read the 'tag' properties of that controls. I reckon those controls are called 'custom pop-up controls' in VBA. It is better if someone shows the basics of handling menus. Thank you.
 
Thank you. But how can we pass a menu button's tag property when that same menu command got clicked. Remember not CommandbarButton but Menubutton
 
Thank you. But how can we pass a menu button's tag property when that same menu command got clicked. Remember not CommandbarButton but Menubutton


A menu item is a child of the commandbar button so you still have to make reference to its parent. I remember doing something like this whilst using Access 2003.

Code:
    Dim cmdBar As CommandBar
    Dim cmdBar As CommandBar
    Dim ctrlCount As Integer
    
    ctrlCount = cmdBar.Controls.count

    If ctrlCount > 1 Then
        For i = 1 To ctrlCount - 1
            If cmdBar.Controls(1).Tag = "window_" Then
            ' Or you can use this: If cmdBar.Controls("NameOfMenu").Tag = "window_" Then
                ' Do something here
            End If
        Next
    End If

You iterate through the command bar collection. Don't use the built-in find method of the command bar, it's slower than what I have specified above because it iterates through ALL command bar items.
 
A menu item is a child of the commandbar button so you still have to make reference to its parent. I remember doing something like this whilst using Access 2003.

Code:
    Dim cmdBar As CommandBar
    Dim cmdBar As CommandBar
    Dim ctrlCount As Integer
    
    Set cmdBar = Application.CommandBars("NameOfMenu/CommandBar")
    ctrlCount = cmdBar.Controls.count

    If ctrlCount > 1 Then
        For i = 1 To ctrlCount - 1
            If cmdBar.Controls(1).Tag = "window_" Then
            ' Or you can use this: If cmdBar.Controls("NameOfMenuItem").Tag = "window_" Then
                ' Do something here
            End If
        Next
    End If
You iterate through the command bar collection. Don't use the built-in find method of the command bar, it's slower than what I have specified above because it iterates through ALL command bar items.


I missed out a crucial line of code. Use the one above instead
 
Hello Friend! Where is the Event procedure? Like mnucmd_click()
 
I don't kno what you want to use it for, so you can put it in the On Click event of a button perhaps. That's up to you to decide. I hope you noticed the comments?
 

Users who are viewing this thread

Back
Top Bottom