Change backcolor if controls are locked

S

SAC

I'd like to loop through the controls on a form and change the backcolor of
a control if it's data is locked.

Should I use the on_current event to call a function?

I'm attempting to modify the control naming function on the Access Web site.

I don't have something right. Here's the function:

Public Function ControlColoring(objForm As Form) As String

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
If c.Properties.Locked = True Then
c.Properties.BackColor = 14671839
Else:
c.Properties.BackColor = 16777215
End If
Next
End With

End Function

Here's the On_Current event:

Dim strName As String
strName = "Forms![" & Me.Name & "]"
ControlColoring strName

Does the form have to be in design view? If so, is there a work around for
this?

Thanks.
 
J

John Smith

That should work, the form does not have to be in design view. Note though
that you need to check c.ControlType before you test c.Locked as not all types
of controls have a locked property.

HTH
John
 
M

Marshall Barton

SAC said:
I'd like to loop through the controls on a form and change the backcolor of
a control if it's data is locked.

Should I use the on_current event to call a function?

I'm attempting to modify the control naming function on the Access Web site.

I don't have something right. Here's the function:

Public Function ControlColoring(objForm As Form) As String

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
If c.Properties.Locked = True Then
c.Properties.BackColor = 14671839
Else:
c.Properties.BackColor = 16777215
End If
Next
End With

End Function

Here's the On_Current event:

Dim strName As String
strName = "Forms![" & Me.Name & "]"
ControlColoring strName

Does the form have to be in design view? If so, is there a work around for
this?


No, this does not require the form to be in design view.

The problem is that you are calling the proedure with the
name of the form, but the procedures argument is declared to
be a form object.

Change the Current event to be just the one line:

ControlColoring Me
 

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

Top