Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

locking subsets of Form fields based on a status field

Status
Not open for further replies.

JaneInMA

Programmer
Nov 3, 2000
104
US
I have forms that need to have data entered but have a field Status (Yes/No) that indicates the data entry is finished. But there are fields that must still be open such as the comment subforms. I am trying to use the tag field to let the form know which fields to lock and the "for each" code to cycle through these.
The form is actually a subform with child subforms of its own. when I try to use this code it locks a test field regardless of whether the status is checked (Closed) or not.

Dim ctrl As control


If Not IsNull(Me.Status.Value) Then
For Each ctrl In Me.Form
'loop thru form to find fields to clear
If InStr(1, ctrl.Tag, "Lock Me") Then
ctrl.Locked = True
End If
Next ctrl
End If


I tried putting an else statement but got this error,
Run Time error438 Object does not support this property or method.

Dim ctrl As control


If Not IsNull(Me.Status.Value) Then
For Each ctrl In Me.Form 'loop thru form to find fields to clear
If InStr(1, ctrl.Tag, "Lock Me") Then
'ctrl = Null
ctrl.Locked = True
Else
ctrl.Locked = False
End If
Next ctrl
End If

Is this doable - if so what is wrong with the code above.
Thanks for your help.
 
I think the problem may be that not all controls have a locked property

try something like
Dim ctrl As Control
For Each ctrl In Me.Form 'loop thru form to find fields to clear
If InStr(1, ctrl.Tag, "Lock Me") Then
'ctrl = Null
ctrl.Locked = True
Else
Select Case ctrl.ControlType
Case acTextBox, acComboBox
ctrl.Locked = False
End Select
End If
Next ctrl
 
Thanks a lot, the control type addition nails it.
Here is the code that works for anyone else interested
Dim ctrl As control
If Me.Status.Value = -1 Then
For Each ctrl In Me.Form 'loop thru form to find fields to clear
If InStr(1, ctrl.Tag, "Lock Me") Then
ctrl.Locked = True
Else
Select Case ctrl.ControlType
Case acTextBox, acComboBox, acSubform
ctrl.Locked = False
End Select
End If
Next ctrl
Else
For Each ctrl In Me.Form
Select Case ctrl.ControlType
Case acTextBox, acComboBox, acSubform
ctrl.Locked = False
End Select
Next ctrl
End If

I like this idea because if god forbid I get forced to add more aspects to this form all I do is add the tag to the field and it gets controlled like all the other fields.
It is so frustrating to tackle a problem like this when it is defeating you but great when it suddenly works and adds functionality.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top