Making a dropdown menu bar? Possible? (1 Viewer)

vbaInet

AWF VIP
Local time
Today, 21:39
Joined
Jan 22, 2010
Messages
26,374
No worries buratti. To be honest I haven't had to run your db yet to see what you've done but when/if I do I will leave you a comment.
 

smig

Registered User.
Local time
Today, 23:39
Joined
Nov 25, 2009
Messages
2,209
personaly I less like this look of the drop down menu as it looks like the right mouse click one.

it is very nice :)
 

steven22554

Registered User.
Local time
Today, 15:39
Joined
Mar 8, 2014
Messages
10
Hi there buratti
It's been a few years since anyone has posted here. I was just wondering if you have done anything else with your Menu Creator, and have you made any upgrades to it? I just downloaded it and it's working great. I'm using it with Access 2010

Thanks
Steven :banghead:
 

x40sarax2ecom

New member
Local time
Today, 13:39
Joined
Feb 7, 2018
Messages
1
Mr. Buratti: Thank you for menu_creator.accdb. I'm migrating and old app to WIN10 64-bit/Office 2010 32-bit 0we developed for Office 2000 that hasn't been updated since 2006. Your sample code helps retain the menu look and feel.
Regards,
x40sarax2ecom
 

benhelfman

New member
Local time
Today, 13:39
Joined
Jan 26, 2019
Messages
2
I have searched this subject far and wide. I ran into the same frustration that I could not get shortcut menus to work like they did in A2003. The solution I have tentatively settled upon is to line up command buttons in a column with all but the top button initially set to visible=false. I also brought all of the buttons to front so that they would appear on top of any other controls in the detail section of the form (just like a menu does). I placed these buttons in the detail section of the form instead of a form header so that they would not take up any more space than the top button.

I then created a Form Level Property (using MZ Tools which I highly recommend) called MenuIsClicked. When the "menu button" meaning the top button is clicked, I then have an if then statement as follows

Code:
Sub cmdOpen_Click()
On Error GoTo Error_Handler

    If Me.MainMenuClicked Then
        Me.cmdViewDocs.Visible = False
        Me.cmdAssignments.Visible = False
        Me.cmdProjects.Visible = False
        Me.btnOpenDoctorsForm.Visible = False
        Me.btnOpenCalendar.Visible = False
        Me.DatesOfInjuryFormButton.Visible = False
        Me.DORFormButton.Visible = False
        Me.SettlementsSubFormButton.Visible = False
        Me.MedicalsSubFormButton.Visible = False
        Me.LiensSubFormButton.Visible = False
        Me.cmdUR.Visible = False
        Me.btnOpenRehabVendor.Visible = False
        Me.cmdFileHandlingPreferences.Visible = False
        Me.OpenMenuSide.Visible = False
        Me.MainMenuClicked = False
    Else
        Me.cmdViewDocs.Visible = True
        Me.cmdAssignments.Visible = True
        Me.cmdProjects.Visible = True
        Me.btnOpenDoctorsForm.Visible = True
        Me.btnOpenCalendar.Visible = True
        Me.DatesOfInjuryFormButton.Visible = True
        Me.DORFormButton.Visible = True
        Me.SettlementsSubFormButton.Visible = True
        Me.MedicalsSubFormButton.Visible = True
        Me.LiensSubFormButton.Visible = True
        Me.cmdUR.Visible = True
        Me.btnOpenRehabVendor.Visible = True
        Me.cmdFileHandlingPreferences.Visible = True
        Me.OpenMenuSide.Visible = True
        Me.MainMenuClicked = True
    End If
    
Exit_Procedure:
    Exit Sub
Error_Handler:
    DisplayUnexpectedError Err.Number, Err.Description & "in Sub cmdOpen_Click in VBA Document Form_CLIENT LIST1"
    Resume Exit_Procedure
    Resume
End Sub

On each of the buttons that are lined up below the top button which are the "items" in my menu, I then run this code on their click event to make the menu "collapse" like a real menu does when an option is selected.

Code:
    Me.cmdOpen.SetFocus
    Call cmdOpen_Click

In order to make the arrow keys work "inside the menu", the tabl order should be set so that the indices of the buttons are sequential.

In order to give the user a cue as to which button he has arrowed down to with the arrow keys, I have the following code in the on enter and on exit events of each button.

Code:
    Me.cmdViewDocs.FontItalic = True

Code:
    Me.cmdViewDocs.FontItalic = False
.

I hope that helps.

Ben
 

zeroaccess

Active member
Local time
Today, 15:39
Joined
Jan 30, 2020
Messages
671
Hello,

I signed up on the forums to add to benhelfman's post.

I implemented a similar idea in an access database recently, using the visible yes/no to show/hide menu items to simulate the functionality many users are accustomed to on the web. I then went one step further and created a set of subroutines that give a hover color effect on the mouse move event.

To dive in to the code to make this work, on a given form where your menu will reside, you'll need something like this for each top-level menu button:

Code:
Private Sub cmdA_Click()
    If Not Me.Line1.Visible = True Then
        HideAllMenus
        Me.Line1.Visible = True
        Me.Line2.Visible = True
        Me.cmd1.Visible = True
        Me.cmd2.Visible = True
    Else
        HideAllMenus
    End If
End Sub

So you are saying if an item is not already visible, then make the items in that column visible, and hide everything else. This lets you "expand" and "collapse" each column with a click.

The "Line1" is simply a line that I added for visual effect in between the menu items. I am checking whether it's visible to trigger the rest of the sequence - but you can use any other menu item in that column to base this on. When any of the buttons are clicked, you want all menu items to disappear, so it runs HideAllMenus, which is in a Module so it is globally accessible:

Code:
Sub HideAllMenus()
    Screen.ActiveForm!cmdUnseen.SetFocus
    On Error Resume Next
    If Screen.ActiveForm.cmd1.Visible = True Then Screen.ActiveForm.cmd1.Visible = False
    If Screen.ActiveForm.cmd2.Visible = True Then Screen.ActiveForm.cmd2.Visible = False
    If Screen.ActiveForm.cmd3.Visible = True Then Screen.ActiveForm.cmd3.Visible = False
    If Screen.ActiveForm.cmd4.Visible = True Then Screen.ActiveForm.cmd4.Visible = False
    If Screen.ActiveForm.Line1.Visible = True Then Screen.ActiveForm.Line1.Visible = False
    If Screen.ActiveForm.Line2.Visible = True Then Screen.ActiveForm.Line2.Visible = False
    If Screen.ActiveForm.Line3.Visible = True Then Screen.ActiveForm.Line3.Visible = False
    If Screen.ActiveForm.Line4.Visible = True Then Screen.ActiveForm.Line4.Visible = False
End Sub

So, if it's visible, make it not visible. I have a transparent command button with no caption called "cmdUnseen" that sits off to the side up in the form header, and first gets the focus to ensure everything works smoothly. You may get errors if your focus is not in the right place before this sequence starts - the menus are also in the form header. You also want to HideAllMenus when the user clicks on the background of the form header and detail section:

Code:
Private Sub Detail_Click()
    HideAllMenus
End Sub

Then for the hover color, you need 2 things. This part is optional.

First,

You will need a subroutine in your globally-accessible Module for each command button:

Code:
Sub cmd1_MouseMove()
    On Error Resume Next
    With Screen.ActiveForm!cmd1
        If Not .ForeColor = TempVars![HoverColor] Then
            .ForeColor = TempVars![HoverColor]
            .HoverForeColor = TempVars![HoverColor]
        End If
    End With
End Sub

You can search for how to use TempVars - but essentially, this method allows you to set a different hover color for different forms, if you wish. You will need one last thing in your Module, this time as a Function because I sometimes want to call it from a macro:

Code:
Function SetHoverColor()

    Dim HoverColor As Long

    On Error Resume Next
    Select Case True
        Case Screen.ActiveForm.Name = "frm1"
            If Not HoverColor = 16758883 Then HoverColor = 16758883
        Case Screen.ActiveForm.Name = "frm2"
            If Not HoverColor = 16758883 Then HoverColor = 16758883
        Case Screen.ActiveForm.Name = "frm3"
            If Not HoverColor = RGB(220, 50, 50) Then HoverColor = RGB(220, 50, 50)
        Case Screen.ActiveForm.Name = "frm4"
            If Not HoverColor = RGB(0, 200, 85) Then HoverColor = RGB(0, 200, 85)
        Case Screen.ActiveForm.Name = "frm5"
            If Not HoverColor = vbYellow Then HoverColor = vbYellow
    End Select
    
    TempVars.Add "HoverColor", HoverColor
End Function

Which is called from each menu item on each form:

Code:
Private Sub cmd1_Click()
    HideAllMenus
    DoCmd.OpenForm "frm1"
    SetHoverColor
End Sub

You probably don't need to SetHoverColor on every button if you are going to use the same color on all forms. It's really just to ensure it changes.

Second, to return the fore color to white when the mouse moves off of each button, you will want the following subroutine to run on the Mouse Move event in both your form header and detail section. Again, put this in a Module so it is globally accessible:

Code:
Sub MenuDefaultColor()
    On Error Resume Next
    If Not Screen.ActiveForm!cmd1.ForeColor = vbWhite Then Screen.ActiveForm!cmd1.ForeColor = vbWhite
    If Not Screen.ActiveForm!cmd1.HoverForeColor = vbWhite Then Screen.ActiveForm!cmd1.HoverForeColor = vbWhite
    If Not Screen.ActiveForm!cmd2.ForeColor = vbWhite Then Screen.ActiveForm!cmd2.ForeColor = vbWhite
    If Not Screen.ActiveForm!cmd2.HoverForeColor = vbWhite Then Screen.ActiveForm!cmd2.HoverForeColor = vbWhite
    If Not Screen.ActiveForm!cmd3.ForeColor = vbWhite Then Screen.ActiveForm!cmd3.ForeColor = vbWhite
    If Not Screen.ActiveForm!cmd3.HoverForeColor = vbWhite Then Screen.ActiveForm!cmd3.HoverForeColor = vbWhite
    If Not Screen.ActiveForm!cmd4.ForeColor = vbWhite Then Screen.ActiveForm!cmd4.ForeColor = vbWhite
    If Not Screen.ActiveForm!cmd4.HoverForeColor = vbWhite Then Screen.ActiveForm!cmd4.HoverForeColor = vbWhite
    If Not Screen.ActiveForm!cmd5.ForeColor = vbWhite Then Screen.ActiveForm!cmd5.ForeColor = vbWhite
    If Not Screen.ActiveForm!cmd5.HoverForeColor = vbWhite Then Screen.ActiveForm!cmd5.HoverForeColor = vbWhite
End Sub

Example of its use in the detail section, simply added via clicking on the detail section of the form, then clicking on the 3 dots by the Mouse Move event and choosing code builder:

Code:
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MenuDefaultColor
End Sub

The menu looks like this, and is copied to other forms so it is always visible, using the exact same button names. You will want your forms to open in tabbed mode, with the tabs not visible in your end-user .accde. When a button is clicked and another form opens, it looks like you are navigating a web page where the menu stays in place. Your use case may vary.

Menu.png


Note there is a blank button as a spacer in between each menu item. This is needed so your mouse goes over the header and detail sections to revert the color to white. Otherwise, as you pass your cursor over, you will end up with multiple items changing color, but not changing back.

Good luck to anyone who sees this...it took me a lot of time to come up with this scheme. You will need to tweak to suit your needs. I hope it provides a foundation that you can work with.
 

geepee.palad

New member
Local time
Today, 13:39
Joined
Mar 17, 2020
Messages
3
Hello zeroaccess, kudos to this on constantly improving on the limited and outdated form design of Access.

I am curious with the UI on the form you've made. can you post the menu on a form? you can leave the code out of it if you don't want to.

Thank you.
 

zeroaccess

Active member
Local time
Today, 15:39
Joined
Jan 30, 2020
Messages
671
Can you explain what you mean by "can you post the menu on a form"?

Also, the code has been cleaned up a little and I now use the tag property to group each menu column.

SQL:
Sub HideAllMenus()
    On Error Resume Next

    Dim ctrl As Control
   
    Screen.ActiveForm!cmdUnseen.SetFocus
   
        For Each ctrl In Screen.ActiveForm.Controls
            Select Case ctrl.Tag
                Case "MenuA", "MenuB", "MenuC", "MenuD", "MenuE", "MenuF"
                    If Not ctrl.Visible = False Then
                        ctrl.Visible = False
                    End If
            End Select
        Next
End Sub
 

geepee.palad

New member
Local time
Today, 13:39
Joined
Mar 17, 2020
Messages
3
Can you explain what you mean by "can you post the menu on a form"?

Also, the code has been cleaned up a little and I now use the tag property to group each menu column.

SQL:
Sub HideAllMenus()
    On Error Resume Next

    Dim ctrl As Control
  
    Screen.ActiveForm!cmdUnseen.SetFocus
  
        For Each ctrl In Screen.ActiveForm.Controls
            Select Case ctrl.Tag
                Case "MenuA", "MenuB", "MenuC", "MenuD", "MenuE", "MenuF"
                    If Not ctrl.Visible = False Then
                        ctrl.Visible = False
                    End If
            End Select
        Next
End Sub


Hi zeroaccess. I wanted to check the properties of the objects (buttons) you've used on the screenshot you've attached. Are they transparent buttons? Are they using the Themes property and those things.

The tag property is an efficient solution.

Thank you.
 

zeroaccess

Active member
Local time
Today, 15:39
Joined
Jan 30, 2020
Messages
671
Hi zeroaccess. I wanted to check the properties of the objects (buttons) you've used on the screenshot you've attached. Are they transparent buttons? Are they using the Themes property and those things.

The tag property is an efficient solution.

Thank you.
They are just command buttons with transparent backgrounds. Nothing special :)
 

owyllie

New member
Local time
Today, 16:39
Joined
Feb 23, 2024
Messages
1
Yes I created it in Access 07 and am unsure how it will react in other versions. I did not try what you have suggested a little whilt back, but only because I got this workin before that (for my particular database at least). I am no expert when it comes to designing and answering questions, and this is actually the first time I am even posting something to possibly help someone else and not asking for help myself. i have gotten so much help from other users here that I was anxious to post something that could possible help someone else, but probably should of debugged it more before posting. If the actual database forms do not work for you, look at the code and try to create your command bars straight from there. I recall in one of the comments I placed an address that gave good information on how to create command bars. What errors are you getting. The entire DB is in access 07 format, and I believe it will not even open on older versions. If thats the case, let me know and I can re-save the db in an older format (probably should of done that in the first place), but Like I stated earlier, I am unclear if this will work or not in older formats.


Yeah I knew there would be errors, but like I was saying to smig above, I was just anxious to get it out there and help someone else. Everytihng I needed it for works fine, but I guess everyone out there would have slightly different uses for it, and I did not incorperate those uses into the design.
I created an account 14 years after your solution was posted just to say thanks for this and to let others know that it's a viable solution. I set the button borders to transparent and aligned them horizontally to mimic the usual menu of most commercial applications. So far the only issue is that the drop-down menus are aligned a little to the right of the main menu button (instead of directly underneath the main menu), but that's likely an easy fix. I'm going to fiddle with it now.
 

Users who are viewing this thread

Top Bottom