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:
The above function only works after the property is set up by this sub:
To turn off shortcut menus:
or True to turn them on.
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)