Temporarily Disabling right-click Shortcut Menus

Orthodox Dave

Home Developer
Local time
Today, 03:54
Joined
Apr 13, 2017
Messages
218
I am setting up message boxes in selected fields on my database, triggered by the MouseDown event (right click), to provide user-friendly help to inexperienced users. (ControlTip text is too short for my purposes.)

This works well - the message box appears - but when the user clicks OK and the message box goes away, the Access default shortcut menu appears.

I want to temporarily disable the shortcut menu while my MsgBox code runs, then reinstate it.

Now I have found code that works to tick or un-tick the "Allow Default Shortcut Menus" box in Current Database Options. It does that beautifully, but has no effect on the menus until the database is re-started! That's not much use really.

Is there some way to refresh or requery the database options, so this takes effect in real time without restarting the database?

Here is the code:
Code:
Public Function ChangeProperty(strPropertyName As String, varPropertyType As Variant, _
varPropertyValue As Variant) As Integer
'Source: https://bytes.com/topic/access/answers/926248-possible-set-access-startup-options-using-vba

'I wanted to disable the Access right-click shortcut menu when I have created my own MsgBox message,
'but not to do this permanently (by un-ticking the "Allow shortcut Menus" box in Options).

On Error GoTo Err_ChangeProperty
Dim MyDB As DAO.Database
Dim MyProperty As DAO.Property
 
Set MyDB = CurrentDb()
 
'Property exists, so set its Value
MyDB.Properties(strPropertyName) = varPropertyValue
ChangeProperty = True
 
Exit_ChangeProperty:
'MsgBox "Exit"
  Exit Function
 
Err_ChangeProperty:
'MsgBox "Err"
  If Err.Number = 3270 Then       'Property not found
    'Since the Property isn't found, create it!
    Set MyProperty = MyDB.CreateProperty(strPropertyName, varPropertyType, varPropertyValue)
    MyDB.Properties.Append MyProperty
      Resume Next
  Else
   'Unknown Error
   ChangeProperty = False
     Resume Exit_ChangeProperty
  End If
End Function

The above function only works after the property is set up by this sub:
Code:
Public Sub ShortcutMenusOnOff()
Const DB_Boolean As Long = 1
    ChangeProperty "AllowShortcutMenus", DB_Boolean, False
End Sub

To turn off shortcut menus:
Code:
ChangeProperty("AllowShortcutMenus", dbBoolean,False)
or True to turn them on.
 
I want to temporarily disable the shortcut menu while my MsgBox code runs, then reinstate it.

Now I have found code that works to tick or un-tick the "Allow Default Shortcut Menus" box in Current Database Options. It does that beautifully, but has no effect on the menus until the database is re-started! That's not much use really.

Is there some way to refresh or requery the database options, so this takes effect in real time without restarting the database?

I believe you are out of luck.
This is one of the startup properties for a database so by definition you have to restart it

I agree with you about ControlTips - also there is a delay before these appear

However, I have a slightly different approach to you.
I use the mouse move event to display 'help' text in a label on selected forms.
That means the message is visible for all users on moving over a control but can be ignored by experienced users.
When users move away, the message disappears automatically

HTH
 
Code:
Private Sub Command1_Enter()
    ShortcutMenu = False
End Sub

Private Sub Command1_Exit(Cancel As Integer)
    ShortcutMenu = True
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = acRightButton Then MsgBox "hello"
End Sub
 
Thanks to both but Static has it - I don't know how I overlooked the simple "ShortcutMenu" property and ended up with all that complicated code.

I had started going down a different route, which was working and I might still use:
Code:
Private Sub EngineerID_KeyPress(KeyAscii As Integer)
If KeyAscii = 63 Then MsgBox (EngCtrl): SendKeys "{ESC}"
End Sub
63 is a question mark and this works perfectly too. The user types a "?" into the text box and up comes the help message box.

This may be simpler than the ShortcutMenu route, because I'd have to find a way to turn off the shortcut menu BEFORE the person right-clicks the box (by then it's too late - I tried it).

Many thanks again for the lightning quick help! :)
 
Hi Static

I'm not sure what you expect to happen with this code.
Obviously the mouse up example event works.
However, which shortcut menu are you disabling / enabling?

If 'allow default shortcut menus' is checked in Database Options, the full list stays visible on entering the control. If unchecked, the full list stays hidden

It also doesn't affect the shortcut menu for a datasheet

Maybe I'm missing something here?
 
This may be simpler than the ShortcutMenu route, because I'd have to find a way to turn off the shortcut menu BEFORE the person right-clicks the box (by then it's too late - I tried it).
I was wrong - it does work in the MouseDown (right-click) event. Then I turn it on again via LostFocus.
So the code is now:
Code:
Private Sub EngineerID_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.ShortcutMenu = False
If Button = acRightButton Then MsgBox (EngCtrl)
End Sub
and
Code:
Private Sub EngineerID_LostFocus()
Me.ShortcutMenu = True
End Sub
And that works perfectly. When I right-click the field, my message box comes up but no Access shortcutmenu when it goes away. But the shortcut menu still works in other fields.

Colin - Static was right - even if the Access Options Allow Short Cut Menus option is ticked, this Me.ShortcutMenu = False allows you to override the setting.
 
Ah I see now
You want to temporarily disable the right click context menu (cut/copy/paste etc)

I was talking about removing the menu items at the top of the screen
(Create / External Data etc)
or in my response to Static querying if he meant disabling the shortcut menu in datasheets (disable/enable the drop down arrows on datasheet headers)

Looks like I had the wrong end of the stick....
 
Sorry if I was unclear. And may need the other end of the stick in future!
 
Not sure whether you were being unclear or me being obtuse...(whatever that means)

As I said before, I call the right click menu the context menu & think of the shortcut menu differently - probably just me.

Anyway Static - no need to respond to my earlier post

Now where did I put that stick?
 

Users who are viewing this thread

Back
Top Bottom