How about hiding the Nav Bar with VB when a form is opened? Here's how:
Private Sub Form_Load()Want to hide both the Navigation Sidebar and the Access Ribbon?
' hide the Navigation SideBar
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
End Sub
Change the above to this:
Private Sub Form_Load()
' hide the Navigation SideBar
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
' hide the Access Ribbon
DoCmd.ShowToolbar "Ribbon", acToolbarNo
End Sub
Oh, but what if you want control over hiding/unhiding the Nav Bar and the Ribbon as the administrator, so you can work on the database?
You've got a few choices. You could put an 'Easter Egg' on your form. Say, for instance, you type a single period in a label someone at the top of the form. It will be barely visible, and probably mistaken for a bit of dust on the monitor, or a glitch in the colors on the form. Change its color to be nearly the same as the form, or even exactly the same, to really reduce its visibility. Then, use the reverse the code above in its 'On Double Click' property to restore the Nav Bar.
Or, you create a logon form to capture users as objects when they first open the program, and set up view levels based on that. Assuming we've logged on as the administrator, and our User.AccessID is 1, then we can create buttons on the form to show or hide the Navigation Bar and Ribbon as follows:
Create two buttons on your form. Name one unhideNavBar_btn, and the other hideNavBar_btn. Place them on top of each other, and set their visible property = No.
Then create two more buttons on your form. Name one unhideRibbon_btn, and the other hideRibbon_btn. Place them on top of each other too, and of course set their visible properties = No also, just like you did above.
When we load the form we'll need to check to see if these buttons should be visible, so amend your On Load event to this:
Private Sub Form_Load()' hide the Navigation SideBar
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
' hide the Access Ribbon
DoCmd.ShowToolbar "Ribbon", acToolbarNo
If User.AccessID = 1 Then ' this is the Administrator account
[unhideNavBar_btn].Visible = True ' show the button to unhide the Nav Sidebar [unhideRibbon_btn].Visible = True ' show the button to unhide the Access Ribbon
End IfEnd Sub
For your buttons themselves, you'll need to add properties to their click events. Here's one example, which you'll need to add and modify for each of the four buttons we created above:
Private Sub unhideNavBar_btn_Click()
' SHOW the Navigation Bar (this is only available to the "Administrator")
DoCmd.SelectObject acTable, , True
hideNavBar_btn.Visible = True ' toggle the button that's visible
select_TM_cbox.SetFocus ' set the focus to another control on your form (rename TM_Cbox to another control on your form)
unhideNavBar_btn.Visible = False ' toggle the button that has the focus
End Sub
No comments:
Post a Comment