Lock / Unlock Bound Controls...
You can use this Function to lock/unlock all the *bound* controls on a Form. Copy/paste this Function into a Module. Remember, do not name the Module the same as the Function.
Private Sub Form_Current()
If (Me.txtStatusID) = "C" Then
fncLockUnlockControls Me, True 'Locked
Else
fncLockUnlockControls Me, False 'Unlocked
End If
End Sub
To call this Function you need a trigger, in the example txtStatusID is used, and then place something like the below in the On_Current event of your form...
The difficult I do immediately, the impossible takes a little bit longer.
Public Function fncLockUnlockControls(frm As Form, LockIt As Boolean)
'From http://www.access-diva.com/tips.html
'Lock or unlock all data-bound controls on form,
'depending on the value of : True = lock; False = unlock.
'Posted in the Newsgroups by Dirk Goldgar Access MVP 2005
On Error GoTo Err_fncLockUnlockControls
Const conERR_NO_PROPERTY = 438
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If Left(.ControlSource & "=", 1) <> "=" Then
.Locked = LockIt
.Enabled = True
End If
End With
Skip_Control: 'come here from error if no .ControlSource property
Next ctl
Exit_fncLockUnlockControls:
Exit Function
Err_fncLockUnlockControls:
If Err.Number = conERR_NO_PROPERTY Then
Resume Skip_Control
Else
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_fncLockUnlockControls
End If
End Function
VBA