L
Leonard Priestley
There have been several occasions when I have found it helpful to check the
collection of controls on a form, looking for any with a particular tag.
This has always worked for me before, but now I have struck a problem. In
the same database I have two forms where I have used this technique in the
same way, and for the same reason. That is: I want to lock some text and
combo boxes and not others, and I want to indicate they are locked by
changing their backcolor. The technique works on one form and produces the
error message "Object doesn't support this property or method" on the other
form. I have spent ages comparing the forms and I can't see anything to
account for this. In fact, the code (quoted below) was copied and pasted
from the form that works to the form with the problem. I'm wondering if the
code I have used is cutting corners in some way that matters on the second
form.
This is the code I am using:
Private Sub LockBox()
'Lock any controls tagged "Lockable"
Dim L As Control
For Each L in Me.Controls
If L.Tag = "Lockable" Then
L.Locked = True
L.BackColor = 15461355
End If
Next
End Sub
The line L.Locked = True seems to work fine, but the line L.BackColor =
15461355 causes the error message. Yet I have used this code to change
both forecolor and backcolor in other forms and have had no problems. Am I
missing out on some aspect of using the control object?
Leonard Priestley
collection of controls on a form, looking for any with a particular tag.
This has always worked for me before, but now I have struck a problem. In
the same database I have two forms where I have used this technique in the
same way, and for the same reason. That is: I want to lock some text and
combo boxes and not others, and I want to indicate they are locked by
changing their backcolor. The technique works on one form and produces the
error message "Object doesn't support this property or method" on the other
form. I have spent ages comparing the forms and I can't see anything to
account for this. In fact, the code (quoted below) was copied and pasted
from the form that works to the form with the problem. I'm wondering if the
code I have used is cutting corners in some way that matters on the second
form.
This is the code I am using:
Private Sub LockBox()
'Lock any controls tagged "Lockable"
Dim L As Control
For Each L in Me.Controls
If L.Tag = "Lockable" Then
L.Locked = True
L.BackColor = 15461355
End If
Next
End Sub
The line L.Locked = True seems to work fine, but the line L.BackColor =
15461355 causes the error message. Yet I have used this code to change
both forecolor and backcolor in other forms and have had no problems. Am I
missing out on some aspect of using the control object?
Leonard Priestley