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

Hide Switchboard items

P: 5
I have a switchboard built with all the items needed. I have a query that captures the current user, compares that to a table and gets the info for that user. If the user is a member of a certain group, say purchasing, I want to hide all switchboard items except for purchasing. Is there a way to do that?
Nov 21 '08 #1
Share this Question
Share on Google+
5 Replies


Expert Mod 2.5K+
P: 2,545
Hi. If you are using the built-in switchboard manager you can't do much in the way of such customisation with it. The switchboard items are stored in the table called Switchboard in the application itself.

The Switchboard wizards that built the switchboard form for you (which is just one form, no matter how many apparently different sets of options are defined) have already generated VBA code to manage the selection of switchboard items. You would not be able to maintain the switchboard using the built-in wizards if you try to set further options for restricting the display of options under your own control.

You would need to devise a custom switchboard for yourself and show/hide items under program control. If you have a look at the code behind the built-in switchboard form you will see that this is not necessarily as straightforward as you may imagine it is.

A better option may simply be to define individual custom forms with suitable buttons and options for each group of users, opening and closing these under program control according to the user group to which the user belongs. You can use DLookup in code to lookup the value of the usergroup from your user query (the one you mention in your post that has all the details about the user and the group to which he or she belongs).

-Stewart
Nov 21 '08 #2

P: 5
Thanks Stewart, I figured as much. How can I hide menu options on a custom form? Do I have to use the form "on load" event to set up if then else's for each user group (there's <10) or what?
Thanks
Emil
Nov 21 '08 #3

ADezii
Expert 5K+
P: 8,597
  1. I'm assuming that you have a single, Access Generated Switchboard with 7 Default Buttons on it named Option1, Option2, ...Option7. If this is not the case, things get a little more complicated.
  2. The trick is not to 'Hide' the Switchboard Buttons but to 'Disable' them depending on the User.
  3. The following code, placed in the Switchboard's Open() Event will enable all 7 Buttons for the Admin User, and disable all Buttons except 5 and 7 for the User named Purchasing:
    Expand|Select|Wrap|Line Numbers
    1. Dim intCounter As Integer
    2.  
    3. 'You can't disable a Control that has the Focus, so divert the
    4. 'Focus to another Control on the Switchboard
    5. Me![cmdViewHistory].SetFocus
    6.  
    7. Select Case CurrentUser()
    8.   Case "Admin"           'Enable All Command Buttons
    9.     For intCounter = 1 To 7
    10.       Me.Controls("Option" & CStr(intCounter)).Enabled = True
    11.     Next
    12.   Case "Purchasing"      'Disable All Buttons except 5 and 7
    13.     For intCounter = 1 To 4
    14.       Me.Controls("Option" & CStr(intCounter)).Enabled = False
    15.     Next
    16.       Me.Controls("Option6").Enabled = False
    17.   Case Else
    18.     'You tell me
    19. End Select
  4. To precisely identify what Buttons were clicked on which Switchboards, I initialize Global Variables to the Caption of the Switchboard and the specific Button Clicked (Lines 4 and 5) which is defined by intBtn in the HandleClicks() Function, as in:
    Expand|Select|Wrap|Line Numbers
    1. Private Function HandleButtonClick(intBtn As Integer)
    2. 'This function is called when a button is clicked.
    3. 'intBtn indicates which button was clicked.
    4. gSwitchboardName = Me.Caption
    5. gButtonClicked = intBtn
    6.  
    7. 'Constants for the commands that can be executed.
    8. Const conCmdGotoSwitchboard = 1
    9. Const conCmdOpenFormAdd = 2
    10. Const conCmdOpenFormBrowse = 3
    11. Const conCmdOpenReport = 4
    12. Const conCmdCustomizeSwitchboard = 5
    13. Const conCmdExitApplication = 6
    14. Const conCmdRunMacro = 7
    15. Const conCmdRunCode = 8
    16.  
    17. '...yadda, yadda, yadda
  5. Let me know how you make out, and if this is what you are looking for.
P.S. - I'm making the assumption that you can handle the Lookup Code for Users/Groups yourself.
Nov 22 '08 #4

P: 5
Thank you for the code. I seem to be lost in Access land. whenever I try to run the code it keeps asking me for a macro! I can't run it in step mode or anything else. Then when I try to open the form, it's giving me an error about the cmdviewhistory field. What is that? What do I change it to? The rest of the code makes sense to me except the macro part and the cmdviewhistory part.
What am I dong wrong????
Emil
Nov 22 '08 #5

ADezii
Expert 5K+
P: 8,597
  1. Then when I try to open the form, it's giving me an error about the cmdviewhistory field. What is that?
  2. Replace cmdViewHistory with the Name of another Command Button on the Switchboard. The idea is to re-direct Focus to an Object other than a Switchboard Command Button.
  3. Replace Admin and Purchasing User Names with those appropriate to your situation.
  4. The code is for Command Buttons named Option1 thru Option7 (Default). If this does not apply to you, rename.
Nov 23 '08 #6

Post your reply

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