If I have code that is almost the same in several forms, I try and use one sub/function and call it from many places. I think the following will do what you want.
Paste the following code into a standard module. Do Not name the module the same as the sub name!!
Code:
Sub EnableDisableControls(frm As Form, pEnableCMD_Buttons As Boolean)
' pIncludeButtons = TRUE -> enable buttons
' pIncludeButtons = False -> disable buttons
Dim rs As DAO.Recordset
Dim permission As String
Dim ctlTmp As Control
Set rs = CurrentDb.OpenRecordset("Select * FROM qry_UserGroup")
permission = rs!UserPermissions
If permission = "Admin" Then
Forms(frm.Name).AllowEdits = True
Else
Forms(frm.Name).AllowEdits = False
On Error Resume Next
For Each ctlTmp In frm.Controls
With ctlTmp
Select Case .ControlType
Case acComboBox, acTextBox
.Enabled = False
Case acCommandButton
.Enabled = pEnableCMD_Buttons
End Select
End With
Next ctlTmp
End If
rs.Close
Set rs = Nothing
End Sub
In each form, in the load event, call the code using:
Code:
Private Sub Form_Load()
' TRUE -> enable buttons
' False -> disable buttons
EnableDisableControls Me, FALSE
'or
' EnableDisableControls Me, TRUE
End Sub
Warning: this is largely untested!!!!