
Originally Posted by
sdel_nevo
Hi guys
I am stopping users from right clicking on specific forms by placing this code into the forms onload event
Code:
If strAccess = "Admin" Then
Me.ShortcutMenu = True
Else
Me.ShortcutMenu = False
End If
the code above works as expected, but I would like to replace this and just call it from a module to cut down on coding
the code I have in my module is this
Code:
Public Function RightClickMenu()
Dim objAllForms As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each objAllForms In dbs.AllForms
If objAllForms.IsLoaded = True And strAccess = "Admin" Then
Me.ShortcutMenu = True
Else
Me.ShortcutMenu = False
End If
Next objAllForms
end function
then I want to call this code when a form opens using the forms on open event
I'm guessing something like this
Code:
Private Sub Form_Load()
'then we run the following button click events
RightClickMenu
End Sub
what I cant get my head around is how I would call the function so that the me.shortcutmenu code works when called from a form
for the love of me I can't work out how to do this
many thanks
Steve
Steve,
I do something similar to set the ribbon and shortcut menu based on the user.
Your original code was very close. To make it work you need to replace the ME with objAllForms .
Like this:
Code:
Public Function RightClickMenu()
Dim objAllForms As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each objAllForms In dbs.AllForms
If objAllForms.IsLoaded = True And strAccess = "Admin" Then
objAllForms.ShortcutMenu = True
Else
objAllForms.ShortcutMenu = False
End If
Next objAllForms
end function
I use a global function to work with forms. I pass a reference to the form object so I can set lots of properties
I would write your function like this:
Code:
Public Function RightClickMenu(frm as Form)
If strAccess = "Admin" Then
frm.ShortcutMenu = True
Else
frm.ShortcutMenu = False
End If
End Function
The way I like to write the code would be:
Code:
Public Function RightClickMenu(frm as Form)
frm.ShortcutMenu = (strAccess = "Admin")
End Function
Call it like this:
Code:
Private Sub Form_Load()
'then we run the following button click events
Call RightClickMenu(Me)
End Sub
Since what you want can actually be done with a single line of code, you can save the overhead of calling a function.