Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show/Hide menus using code? 1

Status
Not open for further replies.

blackduck

Programmer
Jun 11, 2002
119
AU
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.
 
Yes, you can. You can also suppress the shift key (
PropName=AllowFullMenus

Code:
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
   
  ExitLine:
     db.Close
     Set db = Nothing
     Set prp = Nothing
     Exit Sub
   
  ErrorHandler:
     If Err.Number = PROPERTY_NOT_FOUND Then
        ' Create the new property.
        Set prp = db.CreateProperty(PropName, PropType, PropVal)
        db.Properties.Append prp
        Resume Next
     Else
        Resume ExitLine
     End If
   
  End Sub

From:
 
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
 
How are ya blackduck . . .

Example:
Code:
[blue]   CommandBars("[purple][b]MenuName or ToolbarName[/b][/purple]").Enabled = False[/blue]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
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.

SeeThru
Synergy Connections Ltd - Telemarketing Services

 
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?
 
blackduck . . .

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

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
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)

 
blackduck,

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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top