Ally
Registered User.
- Local time
- Today, 18:13
- Joined
- Sep 18, 2001
- Messages
- 617
I have a module, with a sub procedure preventing users with a LevelID of 2 being able to edit any forms, but those with LevelID 1 have full permissions.
Colin originally had this behind one form, but for my purposes I needed it for all forms, which is why, with Fizzio's help it's now in a module.
But ... it's working for text boxes (after putting Me.Refresh after calling the procedure), but not for anything else, like combo boxes or listboxes. I've amended the code to include the ControlTypes I want but it's not making any difference. Sometimes after a few changes, combo boxes will then start preventing AllowEdits, but it seems a bit haphazard.
The strange thing is, when Colin tried it on his one behind the form, it prevents edits to all ControlTypes and he's only expressed it for acTextBox. This is the code in the module:
The procedure is called OnOpen of each form:
Can anyone help please?
Colin originally had this behind one form, but for my purposes I needed it for all forms, which is why, with Fizzio's help it's now in a module.
But ... it's working for text boxes (after putting Me.Refresh after calling the procedure), but not for anything else, like combo boxes or listboxes. I've amended the code to include the ControlTypes I want but it's not making any difference. Sometimes after a few changes, combo boxes will then start preventing AllowEdits, but it seems a bit haphazard.
The strange thing is, when Colin tried it on his one behind the form, it prevents edits to all ControlTypes and he's only expressed it for acTextBox. This is the code in the module:
Code:
Public Sub fAllowEdits(frm As Form)
Dim ctl As Control, Db As Database, r As Recordset
Dim Lev As Integer, intCanEdit As Integer, Nme As String, frmName As String
Set Db = CurrentDb
Set r = Db.OpenRecordset("tblUsers")
msgbox "Current form is " & frm.Name
Call fOSUserName2
Nme = fOSUserName2
Do While Not r.EOF
If Nme = r.Fields("Username") Then
Lev = r.Fields("LevelID")
End If
r.MoveNext
Loop
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acComboBox, acTextBox, acListBox
If Lev = 2 Then
intCanEdit = False
Else
intCanEdit = True
End If
End Select
End With
Next ctl
If intCanEdit = False Then
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
End If
End Sub
The procedure is called OnOpen of each form:
Code:
Call fAllowEdits(Form)
Me.Refresh
Can anyone help please?