Diane said:
I have created a custom menu bar and I want to disable
some of the items on it depending on who signs onto the
system. I have the code that grabs the user name and all
I need is the vb line that will disable the menuitem. I
have been playing with the SetMenuItem, but have not been
having any luck. Please Help!
Thanks,
Diane
Simple example to disable the third item in a menu bar...
Dim MyMenu As Object
Dim MenuItem As Object
Set MyMenu = CommandBars("MenuName")
MyMenu.Controls(3).Enabled = False
For your situation I would recommend assigning Tag properties to all of the
menu items to create "categories" and then you can loop through all of the
items with code similar to the following.
Dim MyMenu As Object
Dim MenuItem As Object
Dim i As Integer
For i = 1 To MyMenu.Controls.Count
Set MenuItem = MyMenu.Controls(i)
Select Case UserName
Case "JohnDoe"
If MenuItem.Tag = "SomeString" Then
MenuItem.Enabled = True
Else
MenuItem.Enabled = False
End If
Case "SomeOtherGuy"
If MenuItem.Tag = "SomeOtherString" Then
MenuItem.Enabled = True
Else
MenuItem.Enabled = False
End If
End Select
Next i
The above would get nasty to maintain if there were more than a couple of
UserName values and/or if they were frequently changing so I can't really
recommend an approach based on the UserName, but the approach for cycling
through and enabling/disabling the menu items would be the same.