Custom Menu Bar - disable items within it

D

Diane

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
 
R

Rick Brandt

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.
 
D

Diane

Thanks for the help! Actually, I have security codes
attached to each user, so I only have to check through 3
levels.

Thanks!
Diane
 
D

Diane

Thanks for the help and you got me one step closer. Now
how do I disable an item within an item. For example
there is a "REPORTS" that they can choose. Under REPORTS
there are listed a dozen reports and some of these should
be disabled depending on the user.
thanks,
Diane
 
M

Marcia

You can assign say a 1 to the Tag property of certain menu items and then make
those menu items visible or not visible programatically---

Dim cbc As Object
For Each cbc In
Application.CommandBars("MyMenu").Controls("File").CommandBar.Controls
If cbc.Tag = "1" Then
cbc.Visible = False
Else
cbc.Visible = True
End If
Next cbc
 
R

Rick Brandt

Diane said:
Thanks for the help and you got me one step closer. Now
how do I disable an item within an item. For example
there is a "REPORTS" that they can choose. Under REPORTS
there are listed a dozen reports and some of these should
be disabled depending on the user.
thanks,
Diane

Actually I've never tried to go down into a sub-menu "branch". I'm sure
it's doable though. I'd have to play around with it a bit to se what the
syntax is.
 
R

Rick Brandt

Rick Brandt said:
Actually I've never tried to go down into a sub-menu "branch". I'm sure
it's doable though. I'd have to play around with it a bit to se what the
syntax is.


Ok, as you're looping through the items on your menu you have to test the
"Type" value. When the type = "10" then the current Item is a sub-menu
"popup" and you can then loop through the controls in that menu nested
within your main loop.


If MenuItem.Type = "10" Then...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top