boblarson
Smeghead
- Local time
- Today, 01:53
- Joined
- Jan 12, 2001
- Messages
- 32,059
You can lock that one using your own code.The thing is there's one field I want to further lock according to user level so let's say the form is unlocked that field might still be locked to certain users...
Look at the function. There is a parameter for form (why we pass ME to it) and then there is a True/Fasle called blnLock. By usingI don't quite understand when you said I just need to call LockUnlock Me, True... when do I call it and why? Does that function mean Apply lock if something is true?
LockUnlock Me, True
that means to run the LockUnlock procedure on the current form and the True tells the function to lock the controls instead of unlocking them.
The red part in the generic function does the locking based on the true or false:
Code:
Function LockUnlock(frm As Form, blnLock As Boolean)
Dim ctl As Control
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
If ctl.TAG <> "DoNotLock" Then
ctl.Locked = [COLOR=red][B]blnLock[/B][/COLOR]
Else
ctl.Locked = False
End If
End Select
Next
End Function
Looking back at this function :
Function LockUnlock(frm As Form, blnLock As Boolean)
Dim ctrl As Control
For Each ctrl In frm.Controls
Select Case ctrl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
If ctrl.Tag <> "DoNotLock" Then
ctrl.Locked = True
Else
ctrl.Locked = False
End If
End Select
Next
End Function
Are you sure I typed in correctly here? Seems a bit weird to me...
You posted the original code I posted instead of the current one which should be in your module. The one I just posted in this post is the one you should have in your standard module.
And what I mean by you can just call the function is that in your Load and On Current events you can just simply use
LockUnlock Me, True
to lock the controls except for the ones with DoNotLock in the Tag. You can then, after that line, unlock any you need based on the user.
So something like this:
Code:
Private Sub Form_Current()
Dim strUserPermissions As String
LockUnlock Me, True
strUserPermissions = Nz(Dlookup("UserPermission", "tblPermissions", "[UserName]=" & Chr(34) & VBA.Environ("username") & Chr(34)),"")
If strUserPemissions <> vbNullString Then
Select Case strUserPermissions
Case "EditFields1"
Me.Control1Name.Locked = False
Case "EditFields3"
Me.AnotherControlName.Locked = False
End Select
End If
End Sub
That is just a real simple sample (the permissions stuff is just something I made up to show you what you can do).
And to unlock you just call the
LockUnlock Me, False
I hope that helps.