Change backcolor if controls are locked

  • Thread starter Thread starter SAC
  • Start date Start date
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.
 
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
 
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
 
Back
Top