How do you disable ctrl+c for certain users? (This should be done for the whole database and not just a single form or report)
This is what I got so far:
Public Function ctrlC()
'prevent unauthorised users from copying data using the ctrl + c shortcut
If ActiveUserLevel < 2 Then
'disalbe ctrl + c
MsgBox "crtl c disabled"
Else
'allow user to use ctrl + c
DoCmd.RunCommand acCmdCopy 'Error: "The cmd or action copy isn't available right now"
End If
End Function
PS: I realize you could use the KEY DOWN event in a form, but I'm looking for a more efficient solution (I don't want to call the key down method on 100 different forms and possibly missing some of them...)
UPDATE
As inspired by Sion.D.P's comment another idea was to build 2 macros. One that disable ctrl+c and another that is blank, then rename them depending on the userAccessLevel with this function:
Public Sub enableUserShortcuts(val As Boolean)
On Error Resume Next:
'swap macro names to enable/disable user shortcut keys
If val = False Then
'disable user shorcuts
DoCmd.RunMacro "AutoKeys_DisableUserShortcuts" 'test if macro needs to be loaded
If err.number = 0 Then
DoCmd.Rename "AutoKeys_Blank", acMacro, "AutoKeys" 'save old macro
DoCmd.Rename "AutoKeys", acMacro, "AutoKeys_DisableUserShortcuts" 'load macro
End If
Else
'enable user shorcuts
DoCmd.RunMacro "AutoKeys_Blank" 'test if macro needs to be loaded
If err.number = 0 Then
DoCmd.Rename "AutoKeys_DisableUserShortcuts", acMacro, "AutoKeys" 'save old macro
DoCmd.Rename "AutoKeys", acMacro, "AutoKeys_Blank" 'load macro
End If
End If
err.number = 0
DoCmd.RunMacro "AutoKeys"
End Sub
Or to import xml macro files with a function(https://stackoverflow.com/a/13104045/5148062):
Public Sub enableUserShortcuts(val As Boolean)
'swap macro names to enable/disable user shortcut keys
If val = False Then
'disable user shorcuts
LoadFromText acMacro, "AutoKeys", "C:\New folder\AutoKeys_DisableUserShortcuts.xml"
Else
'enable user shorcuts
LoadFromText acMacro, "AutoKeys", "C:\New folder\AutoKeys_Blank.xml"
End If
End Sub
The problem with both of the last 2 'solutions' are that the database doesn't seem to update once the above rename/import is done. You got to close the whole db and open it up again for it to work. If I don't close & reopen I get the following error: "YourDbName cant find the macro ^c in the macro group autokeys"