Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Show/Hide menus using code?

Show/Hide menus using code?

Show/Hide menus using code?

Is there a way, using code, to show the menus.

I have my own login security setup and have used the Tools>Startup> uncheck allow menus to hide the database window and other menus. (ps. I know shift bypass kills all of this - damn!).

I have two buttons with the code below to show/hide the database window and that part works fine.
'To show the database window
    DoCmd.SelectObject acTable, , True

'To Hide the database window
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowHide

I just want to add some more code to be able to show and hide the menus as well.

RE: Show/Hide menus using code?

Yes, you can. You can also suppress the shift key (http://www.mvps.org/access/general/gen0040.htm)



Public Sub SetProp(PropName As String, PropVal As Variant, Optional PropType = dbText)
     Dim db As Object
     Dim prp As Object
     Dim strTitle As String
     Const PROPERTY_NOT_FOUND As Integer = 3270
     On Error GoTo ErrorHandler
     Set db = CurrentDb
     ' Try to set the property. If it fails, the property does not exist.
     db.Properties(PropName) = PropVal
     Set db = Nothing
     Set prp = Nothing
     Exit Sub
     If Err.Number = PROPERTY_NOT_FOUND Then
        ' Create the new property.
        Set prp = db.CreateProperty(PropName, PropType, PropVal)
        db.Properties.Append prp
        Resume Next
        Resume ExitLine
     End If
  End Sub

From: http://wiki.lessthandot.com/index.php/Setting_Start-Up_Options_Using_VBA

RE: Show/Hide menus using code?

Thanks Remou, sorry for late reply. I read your reply and the links but I think this goes a bit beyond my vba skills/understanding.

I went back to using the Tools>startup options and unchecked all the boxes. This worked fine because it still left a small menu, eg the user could still see file, print.

I still want to be able to use code to show the database window, and full menu (ie the one that has file>get external data). Using a button I have setup which is only visible to certain users.

The code I put in the button onclick event is as follows, but it doesnt put back the full menu or toolbars it just seems to ignore it (I copied the code from somewhere)

'Unhide the database window (this works)
   DoCmd.SelectObject acTable,,True
'Unhide menu bar (doesnt work)
   DoCmd.ShowToolbar "Menu Bar", acToolbarYes
'also tried (doesnt work)
   CommandBars.activeMenuBar.Enabled = true

RE: Show/Hide menus using code?

Hi Remou

I current have the default toolbars disabled - will you function allow me to re-enable them for full edit mode?

At the moment I have to close the database and re-open wit hthe bypass key, but that would be a neater way to do it.

Synergy Connections Ltd - Telemarketing Services


RE: Show/Hide menus using code?

Thanks AceMan
It didn't quite work. It may have something to do with me unchecking all the boxes via the tools>startup options.

If I go in via the shift bypass method, I can use your code to hide the full menu bar, then I can use your code to show the full menu bar. I made two buttons CommandBars("Menu Bar").Enabled=True and another =False

This could actually be a better solution. But then I like using the tools>startup uncheck because it leaves just a short menu which allows users to have the print and print preview which is needed for reports.

Id like to use your code, not the startup options, but any idea how I can make just that short default menu stay?

RE: Show/Hide menus using code?

blackduck . . .

Your easiest solution (no code required) would be to design your own Custom Menu Bar for this. Then in StartUp Options select the custom bar name and your done. When you open the form its the custom bar thats displayed!

Your Thoughts? . . .

See Ya! .  .  .  .  .  .

Be sure to see thread181-473997: How To Get Good Answers To Your Questions  Worthy Reading! thumbsup2
Also FAQ181-2886: How can I maximize my chances of getting an answer?  Worthy Reading! thumbsup2

RE: Show/Hide menus using code?

Yip Yah!  Big hug to TheAceMan1.

Here is what I have done:

Created custom menu bar (with just page setup, print preview, print).
Startup options:
- Menu Bar =(default) DO NOT change this to your new one. It has to load first otherwise you cant get it to show again using code.
- checked Allow full menus, allow shortcut menu.
- unchecked everything else.
- Display form/page = eg.frmMainMenu

In the onOpen event of my form eg.frmMainMenu, code:
'Hide the default menu bar
    CommandBars("menu bar").Enabled = False

Therefore, when the db is open, my form appears, my custom menu bar is there and nothing else (looks great!)

I created another form only visible to certain users, and coded two buttons as follows:
Private Sub cmdShow_Click()
'Show the database window
    DoCmd.SelectObject acTable, , True
'Show full menu bar
    CommandBars("menu bar").Enabled = True
End Sub

Private Sub cmdHide_Click()
'Hide the database window
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowHide
'Hide full menu bar
    CommandBars("menu bar").Enabled = False
End Sub

Now my usual users have access to print options but nothing else. My power users have complete access to the database and can import external data etc which is what I wanted.

what a relief
thanks heaps to everyone (especially TheAceMan1 who kept me thinking outside the square)


RE: Show/Hide menus using code?


your solution is exactly what I am attempting. Using Access 2003 and its so-called Help, I have not been able to find how to create a customer menu bar. I can create a custom toolbar and custom menu on the standard/default menu bar.

I know in situations such as this, there is always a quick solution that normally is under my nose. Would you please point my nose in the right direction as to how a custom menu bar may be created?

Thanks in advance for your courtesy.

RE: Show/Hide menus using code?

OK; so I just needed to look a little further. Another thread provided the clue I needed. I'm on my way. Sorry you needed to read through this unneeded post.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close