Ben said:
I have a bunch of fields on a form, from combo boxes, to memo fields. I
want
to click a button that will lock the fields. Then click another button to
unlock the fields.
I have the following for locking:
Me!WARID.Locked = False
I get the following error message:
Compile Error
Method or data member not found
What is the problem? What do I need to do to fix this?
Where was that line of code located? if it was in the form's code module,
and the form has a text box, combo box, or list box named "WARID", then I
don't see why you would get that message. If, on the other hand, the code
is in a standard module, or in some other form, or if "WARID" is not the
correct name of the form, then that might explain the error.
Based on what you say you're trying to do, you may find the following
function useful:
'------ start of code ------
Public Function fncLockUnlockControls(frm As Form, LockIt As Boolean)
' Lock or unlock tagged controls on form <frm>,
' depending on the value of <LockIt>: True = lock; False = unlock.
On Error GoTo Err_fncLockUnlockControls
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If "," & .Tag & "," Like "*,LOCK,*" Then
.Locked = LockIt
End If
End With
Next ctl
Exit_fncLockUnlockControls:
Exit Function
Err_fncLockUnlockControls:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_fncLockUnlockControls
End Function
'------ end of code ------
You would identify the controls to be locked/unlocked at design time by
putting the word "LOCK" in their Tag properties (on the Other tab of the
control's property sheet). To lock all the tagged controls, you would
execute this line of code from a command button on the form:
fncLockUnlockControls(Me, True)
and unlock them with this line of code:
fncLockUnlockControls(Me, False)
Please note: I just modified that code from a somewhat different version of
the function, so I haven't tested it and may have made some mistakes in
editing it.