Disable Certain Menu Items in a Custom Built Menu

Robert Dunstan

Mr Data
Local time
Today, 12:21
Joined
Jun 22, 2000
Messages
291
Good morning all

I have a database which uses a custom built menu and not any of the Access standard menus. When a user starts up the database he/she is required to login with a username and password. When logged in the permission level for the user is retrieved from the table and stored in a public variable. The value of this variable is tested when the user tries to open any of the forms to see if they have the permission to do so.

Because the application is menu driven I would like to be able to program the custom menu to only enable the options available to the user based on permission level.

Any help / advice would be much appreciated.
 
As a starting block, I was able to toggle the visibility of a certain menu by hiding it using the following
Dim MyMenu as string
MyMenu = "Whatever"
TheButton = "E&xit"
CommandBars(MyMenu).Controls(TheButton).Visible = Not (CommandBars("Ian").Controls("E&xit").Visible)

For your problem, you could use the tag property of each menu option to enable/disable appropriately by looping through the controls(giving the control the tag for the lowest permission level required to use it would seem apt)

Note that the CommandBar Controls collection starts at 1, not 0.

Just a starting point.

Ian
 
Ian,

Thanks for the reply. I'll use your suggestion as starting point and if I run into anymore problems I'll post on this thread again.

Rob
 
Ian

Thanks for the pointer. I managed to work it out by looking at the on-line help and after pulling out more than several strands of hair!!! here's the code that made it work:

Dim Menu As Variant
Dim ctl As Variant

Menu = "Global Menu"
Set ctl = CommandBars(Menu).Controls("&Timesheets")
If Permission >= 2 Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If

Set ctl = CommandBars(Menu).Controls("&File")
ctl.Enabled = True

Set ctl = CommandBars(Menu).Controls("&Orders")
If Permission >= 1 Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If

Set ctl = CommandBars(Menu).Controls("&Reports")
If Permission >= 1 Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If

Set ctl = CommandBars(Menu).Controls("System &Administration")
If Permission >= 9 Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If

Set ctl = CommandBars(Menu).Controls("&Suppliers")
If Permission >= 1 Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If

I took a while to figure it out and there is probably a more simpler way of coding the above but hey this works for me.

Thanks again

Rob
 

Users who are viewing this thread

Back
Top Bottom