Peculiar problem with Shortcut Menu Bar

WaiveIt

Registered User.
Local time
Today, 14:20
Joined
Dec 2, 2013
Messages
58
Hey all,
I have a main form 'frmLIC' which holds several subforms. I am using a msoBarPopup to hold 'Cut', 'Copy', 'Paste', and 'Hint'.

Code:
'Create clipboard menuSub createMenu()
If dbgMode Then On Error GoTo Err_H:
    CommandBars("GeneralClipboardMenu").Delete
    
    Dim cmb As CommandBar
    Dim ctlCBarButton As CommandBarButton

      
    Set cmb = CommandBars.Add("GeneralClipboardMenu", msoBarPopup, False, False)
    Set ctlCBarButton = cmb.Controls.Add(Type:=msoControlButton)

        With cmb
            .Controls.Add msoControlButton, 21, , , True  ' Cut
            .Controls.Add msoControlButton, 19, , , True  ' Copy
            .Controls.Add msoControlButton, 22, , , True  ' Paste
        End With
        With ctlCBarButton
            .Caption = "Hint"
            .FaceId = 124
            .Visible = True
            .OnAction = "controlHelp"
        End With
        
        
        
    Set cmb = Nothing
Exit_H:
   Exit Sub
Err_H:
       MsgBox "Please write this down:" & vbNewLine & vbNewLine & "1) " & Err.Number & Err.Description & vbNewLine & vbNewLine & "2) " & _
       "createMenu", vbCritical
       DoCmd.Close acForm, Screen.ActiveForm.Name
Resume Exit_H
End Sub

Sub getRightClick(ByVal actFrm As Form)
If dbgMode Then On Error GoTo Err_H:
    
    Dim ctl As Control
    For Each ctl In actFrm.Controls
        If TypeOf ctl Is TextBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is ComboBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is CommandButton Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is SubReport Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        
    Next
    
Exit_H:
   Exit Sub
Err_H:
       MsgBox "Please write this down:" & vbNewLine & vbNewLine & "1) " & Err.Number & Err.Description & vbNewLine & vbNewLine & "2) " & _
       "createMenu", vbCritical
       DoCmd.Close acForm, Screen.ActiveForm.Name
End Sub

That code works for some of the subforms on my main form, but does not work for others. And I cannot figure out why.
Can anybody help me?

Please review the attached db. "Right Click" the controls in Person, Address, Phone, or Email and you'll notice a custom Shortcut Menu Bar. If you "Right Click" in Auto Policy, Auto Quote, Home Policy, Home Quote, Action Log, or Notes you will get the standard Shortcut Bar (or none in the Runtime).
The sample form is full of errors that are from a lack of data. Don't worry about them
 

Attachments

Last edited:
Look are your error handling . . .
Code:
On Error Resume Next
. . . so guess what happens if there is an error in your code? You never find out about it. I'll download your db and see, but almost certainly there is an error later in that routine that kills it, but you've suppressed it's ability to tell you so.
 
Not sure what that was but I decompiled it and it seems to work now. It looked like there was a breakpoint set on that createmenu routine that never got erased, so when I opened your db, code execution stopped at that line and never built the popup. I've seen that before, that you clear a breakpoint, but it doesn't actually go away.

With compilation, as I understand it, your code gets converted to machine language, but in order to save time Access rarely compiles your whole project at once. Apparently this can result in the compiled parts of the project to get out of sych with your source code and other compiled parts.

To decompile, start access directly with the decompile switch, so open the windows Run... dialog or create a shortcut with this as the target . . .
Code:
"C:\Program Files\Microsoft Office\OfficeXX\MSACCESS.EXE" /decompile
That will start access itself without a current database, then load your database, and access will recompile all your modules. Then, I typically do a compact and repair too, and you'll notice the file get a fair bit smaller too.

Cheers,
 
I updated the error handling in both subroutines attempting to ID any errors, but nothing showed up.

I also decompiled and recompiled the vba with "C:\Program Files\Microsoft Office 15\root\office15\MSACCESS.EXE" /decompile

The weird thing is that I get the Shortcut Menu on some of the subforms. (Person, Address, Phone, and Email). I don't get the Shortcut Menu on (AutoP, AutoQ, HomeP, HomeQ, ActionLog, & Note)
 
OK I figured it out. I had to create a second routine for the subforms.

Code:
Sub getRightClick(ByVal actFrm As [U]Form[/U])
If dbgMode Then On Error GoTo Err_H:
    
    Dim ctl As Control
    For Each ctl In actFrm.Controls
        If TypeOf ctl Is TextBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is ComboBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is CommandButton Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is SubReport Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        
    Next
    
Exit_H:
   Exit Sub
Err_H:
       MsgBox "Please write this down:" & vbNewLine & vbNewLine & "1) " & Err.Number & Err.Description & vbNewLine & vbNewLine & "2) " & _
       "createMenu", vbCritical
       DoCmd.Close acForm, Screen.ActiveForm.Name
End Sub

Sub getRightClickSubF(ByVal actFrm As [U]SubForm[/U])
If dbgMode Then On Error GoTo Err_H:
    
    Dim ctl As Control
    For Each ctl In actFrm.Controls
        If TypeOf ctl Is TextBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is ComboBox Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is CommandButton Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If
        If TypeOf ctl Is SubReport Then
            ctl.ShortcutMenuBar = "GeneralClipboardMenu"
        End If

        
    Next
    
Exit_H:
   Exit Sub
Err_H:
       MsgBox "Please write this down:" & vbNewLine & vbNewLine & "1) " & Err.Number & Err.Description & vbNewLine & vbNewLine & "2) " & _
       "createMenu", vbCritical
       DoCmd.Close acForm, Screen.ActiveForm.Name
End Sub

So weird because I'm getting a Shortcut Menu on 4 subforms using the Form version. These are subforms with a "table" record source. Any subform with a "query" record source needs a different shortcut menu callout. The Table vs. Query subforms must load differently; IDK.
 
Last edited:
The only ones where I don't see your shortcut menu are the ones where it is not set in the activate event.
 

Attachments

The only ones where I don't see your shortcut menu are the ones where it is not set in the activate event.

That is why this issue is so weird.

I was not seeing my Shortcut Menu on 5 subforms & 1 subreport (frmAutoPolicy, frmAutoQuote, frmHomePolicy, frmHomeQuote, frmActionLog, & rptNote. The record source for these subforms are queries) where I set the Shortcut menu on the Activate Event. And I was seeing the Shortcut menu on 4 subforms(frmPerson, frmAddress, frmPhone, & frmEmail. The record source for these subforms are tables)

Either way I changed my approach and now set the Shortcut Menu for the MainForm and SubForm on the same MainForm event using 'getRightClick' AND 'getRightClickSubF' (see post above) rather than setting the Shortcut Menu within each subform.

Code:
Sub MainForm_Current
 Call getRightClick(Forms!MainForm)
 Call getRightClickSubF(Forms!MainForm!SubForm)
etc.
End Sub
 

Users who are viewing this thread

Back
Top Bottom