By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

How to set read only custom menu bar

benchpolo
100+
P: 142
I have a custom menu bar in MSAccess (DeskOrgz> and this menu bar contains several submenu bars. I also have a user login screen where the users are defined by level of access such as '1' for admin, '2' for supervisor, '3' for regular users. How do i set selected menu bars to be "read-only" if the user access level is "3".

Thanks.
Oct 15 '07 #1
Share this Question
Share on Google+
13 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
I have a custom menu bar in MSAccess (DeskOrgz> and this menu bar contains several submenu bars. I also have a user login screen where the users are defined by level of access such as '1' for admin, '2' for supervisor, '3' for regular users. How do i set selected menu bars to be "read-only" if the user access level is "3".

Thanks.
Set the tag on all the menu items you want to hide as 1 and something like the following should work. MenuName refers to the name of each menu group.

Expand|Select|Wrap|Line Numbers
  1.     ' if user level access is 3
  2. Dim cbc As Object
  3.  
  4.     ' Hide items with Tag 1 in the 
  5.     For Each cbc In Application.CommandBars("DeskOrgz").Controls("MenuName").CommandBar.Controls
  6.         If cbc.Tag = "1" Then
  7.             cbc.Visible = False
  8.         Else
  9.             cbc.Visible = True
  10.         End If
  11.     Next cbc
  12.  
Oct 15 '07 #2

benchpolo
100+
P: 142
Is the Controls("MenuName").CommandBar.Controls part of the line code For Each cbc In Application.Commandbars("DeskOrgz").Controls? When I compile it i'm getting "Invalid Procedure call argument" (code below).

I'm putting this code on FORM LOAD.

Private Sub Form_Load()
DoCmd.Maximize

Dim cbc As Object

For Each cbc In Application.CommandBars("Pageant").Controls("TOP 8").CommandBar.Controls
If cbc.Tag = "1" Then
cbc.visiblae = False
End If
Next cbc
End Sub

"Pageant" is the menu bar name and "TOP 8" is the sub-menu of "Reports" menu.

Thanks.
Oct 15 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Try this first ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim cbc As Object
  3.  
  4.               DoCmd.Maximize
  5.  
  6.     For Each cbc In Application.CommandBars("DeskOrgz").Controls("Pageant").CommandBar.Controls("TOP 8").CommandBar.Controls
  7.         If cbc.Tag = "1" Then
  8.             cbc.Visible = False
  9.         End If
  10.     Next cbc
  11.  
  12. End Sub
  13.  
If that doesn't work try this...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Load()
  2. Dim cbc As Object
  3.  
  4.               DoCmd.Maximize
  5.  
  6.     For Each cbc In Application.CommandBars("DeskOrgz").Controls("Pageant").CommandBar.Controls
  7.         If cbc.Tag = "1" Then
  8.             cbc.Visible = False
  9.         End If
  10.     Next cbc
  11.  
  12.  End Sub
  13.  
Oct 15 '07 #4

benchpolo
100+
P: 142
mmccarthy it works! .. another question, if I may, let say i have a menu bar "FILE" with sub-menu "Print Preview", and a menu bar of "REPORTS" with a sub-menu of "TOP 8".

Question 1: How would I hide these menu bar if they are located in different command bars?

Question 2: If I want to unhide it can do i add a nested IF statement or SELECT case inside the FOR loop?

Your assistance is greatly appreciated!

Thanks.
Oct 15 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
mmccarthy it works! .. another question, if I may, let say i have a menu bar "FILE" with sub-menu "Print Preview", and a menu bar of "REPORTS" with a sub-menu of "TOP 8".

Question 1: How would I hide these menu bar if they are located in different command bars?

Question 2: If I want to unhide it can do i add a nested IF statement or SELECT case inside the FOR loop?

Your assistance is greatly appreciated!

Thanks.
Did the first or the second option work? Or did both?
Oct 15 '07 #6

benchpolo
100+
P: 142
This one works

Private Sub Form_Load()
Dim cbc As Object

DoCmd.Maximize

For Each cbc In Application.CommandBars("DeskOrgz").Controls("Page ant").CommandBar.Controls
If cbc.Tag = "1" Then
cbc.Visible = False
End If
Next cbc
End Sub

I modified the code to...

Function hidemybar()
Dim cbc As Object

For Each cbc In Application.CommandBars("Pageant").Controls("&Repo rts").CommandBar.Controls
If cbc.Tag = "1" Then
cbc.Visible = True
Else
cbc.Visible = False
End If
Next cbc
End Function
Oct 15 '07 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
What happens if you do this ?

Expand|Select|Wrap|Line Numbers
  1. Function hidemybar()
  2.     Dim cbc As Object
  3.  
  4.     For Each cbc In Application.CommandBars("Pageant").Controls
  5.         If cbc.Tag = "1" Then
  6.             cbc.Visible = True
  7.         Else
  8.             cbc.Visible = False
  9.         End If
  10.     Next cbc
  11. End Function
Oct 15 '07 #8

benchpolo
100+
P: 142
It still works, but it hides the control.. what I wanted to accomplish is the "greyed out" the control for a specific user level, which in this case I replace the "VISIBLE" to "ENABLE". Then I created a button inside the form (which is also based on user login level) to ENABLE or DISBALE the command bar.

Thanks for all your assistance.
Oct 15 '07 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
It still works, but it hides the control.. what I wanted to accomplish is the "greyed out" the control for a specific user level, which in this case I replace the "VISIBLE" to "ENABLE". Then I created a button inside the form (which is also based on user login level) to ENABLE or DISBALE the command bar.

Thanks for all your assistance.
Sounds good, glad you have it working.
Oct 15 '07 #10

benchpolo
100+
P: 142
mmcarthy, I have another question. What if I have a menu bar called Administration and a sub-menu bar under Administration called Process.

Question? How do I hide the menu bar inside the sub-menu bar? The code you provided me (thanks again dude) only controls the layers of menu bar under the main menu bar.

Thanks.
Oct 16 '07 #11

MMcCarthy
Expert Mod 10K+
P: 14,534
mmcarthy, I have another question. What if I have a menu bar called Administration and a sub-menu bar under Administration called Process.

Question? How do I hide the menu bar inside the sub-menu bar? The code you provided me (thanks again dude) only controls the layers of menu bar under the main menu bar.

Thanks.
I don't think you can do it all in one loop. A second piece of code as follows should do it.

Expand|Select|Wrap|Line Numbers
  1. Function hidemybar()
  2.     Dim cbc As Object
  3.  
  4.     For Each cbc In Application.CommandBars("Pageant").Controls("Administration") .CommandBar.Controls("Process").CommandBar.Controls
  5.         If cbc.Tag = "1" Then
  6.             cbc.Visible = True
  7.         Else
  8.             cbc.Visible = False
  9.         End If
  10.     Next cbc
  11. End Function
Oct 16 '07 #12

benchpolo
100+
P: 142
It works! thanks a lot . you're the best.
Oct 16 '07 #13

MMcCarthy
Expert Mod 10K+
P: 14,534
It works! thanks a lot . you're the best.
You're welcome.
Oct 16 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.