Lock Form

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

On the suggestion of another thread I placed the word LOCK on each of my
controls TAG.

On the Form event Current I placed the following code. I get run-time error
438 Object doesn't support this property.

What I am trying to do is Lock all items on my form if the "EDI_Complete"
Check box is TRUE.

Can anyone offer me a suggested solution?

Thanks
Matt

Private Sub Form_Current()

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "LOCK" Then
If Me.EDI_Complete = True Then
ctl.Locked = True
ctl.ForeColor = vbBlue
Else
ctl.Locked = False
ctl.ForeColor = vbGreen
End If
End If
Next ctl


End Sub
 
D

Douglas J. Steele

I don't believe every control has a Tag property. You'll have to put in
error trapping to determine which control(s) cause the error, and ensure
that you don't look at the Tag property for those controls. (Look at the
ControlType property if you need to eliminate certain controls)
 
M

Marshall Barton

Douglas said:
I don't believe every control has a Tag property. You'll have to put in
error trapping to determine which control(s) cause the error, and ensure
that you don't look at the Tag property for those controls. (Look at the
ControlType property if you need to eliminate certain controls)


I think all the Access controls have the Tag property,
though some ActiveX controls might not.

However, there are some controls that do not have a Locked
(e.g. label) or ForeColor (e.g. checkbox) property.

If a control does not have the Locked property, it should
not be included in the set of controls with "LOCK" in the
Tag property.

An alternative is to use different values in the Tag
property. E,g, "LOCK" for controls that need to be locked
and "FORE" for controls that need to change color. For
those controls that need both, set their Tag to "LOCK;FORE"
The code could then look like:

For Each ctl In Me.Controls
If ctl.Tag Like "*LOCK*" Then
ctl.Locked = Me.EDI_Complete
End If
If ctl.Tag Like "*FORE*" Then
If Me.EDI_Complete = True Then
ctl.ForeColor = vbBlue
Else
ctl.ForeColor = vbGreen
End If
End If

Error handling is a good idea regardless of how the problem
is addressed.
 
D

Douglas J. Steele

Marshall Barton said:
I think all the Access controls have the Tag property,
though some ActiveX controls might not.

However, there are some controls that do not have a Locked
(e.g. label) or ForeColor (e.g. checkbox) property.

If a control does not have the Locked property, it should
not be included in the set of controls with "LOCK" in the
Tag property.

An alternative is to use different values in the Tag
property. E,g, "LOCK" for controls that need to be locked
and "FORE" for controls that need to change color. For
those controls that need both, set their Tag to "LOCK;FORE"
The code could then look like:

For Each ctl In Me.Controls
If ctl.Tag Like "*LOCK*" Then
ctl.Locked = Me.EDI_Complete
End If
If ctl.Tag Like "*FORE*" Then
If Me.EDI_Complete = True Then
ctl.ForeColor = vbBlue
Else
ctl.ForeColor = vbGreen
End If
End If

Error handling is a good idea regardless of how the problem
is addressed.

Yeah, I believe you're correct, Marsh.
 
M

mattc66 via AccessMonster.com

That works thanks - How would I lock a subform?

Marshall said:
I think all the Access controls have the Tag property,
though some ActiveX controls might not.

However, there are some controls that do not have a Locked
(e.g. label) or ForeColor (e.g. checkbox) property.

If a control does not have the Locked property, it should
not be included in the set of controls with "LOCK" in the
Tag property.

An alternative is to use different values in the Tag
property. E,g, "LOCK" for controls that need to be locked
and "FORE" for controls that need to change color. For
those controls that need both, set their Tag to "LOCK;FORE"
The code could then look like:

For Each ctl In Me.Controls
If ctl.Tag Like "*LOCK*" Then
ctl.Locked = Me.EDI_Complete
End If
If ctl.Tag Like "*FORE*" Then
If Me.EDI_Complete = True Then
ctl.ForeColor = vbBlue
Else
ctl.ForeColor = vbGreen
End If
End If

Error handling is a good idea regardless of how the problem
is addressed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to lock/unlock controls? 3
block Form 4
lock property 1
Locking a field 6
lock fields 1
List All Controls On Form 3
Need replacement of ME 6
On Click Revisited 8

Top