loop through controls in Access 2007 form (1 Viewer)

huliman

New member
Local time
Today, 06:02
Joined
Dec 10, 2009
Messages
3
Hi I need help!
I'm need to loop through the lables on a form and initially set them all so that their backcolor is white.

Then I need to loop through a DAO recordset and for each record where the id matched the id of a label I need ti change the colour to red.

I though i knew how to do this but even the code below fails! It sets the colour of the first lable then does nothing yet it is looping through them all.

What is going on here please?

Code:
Dim lngRed As Long, lngWhite As Long
lngRed = RGB(255, 0, 0)
lngWhite = RGB(255, 255, 255)
Dim ctl As Control
  
For Each ctl In Me.Detail.Controls
With ctl
        If ctl.ControlType = acLabel Then
         Debug.Print ctl.Name
        .BackColor = lngRed
        End If
End With
Next ctl
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:02
Joined
Sep 12, 2006
Messages
15,660
it looks OK - how many labels are you seeing? - note that you are only processing cobtrols in the DETAIL section of the form - not the header or footer
 

huliman

New member
Local time
Today, 06:02
Joined
Dec 10, 2009
Messages
3
Thanks for the rapid response, gemma-the-husky - I worked out what the problem was about 20 minutes ago - I had the label background types set to transparent on all the labels except the first so that was the only one that the colour change actually appeared on! I feel really stupid for not thinking about that in the first place but I'm still not sure why one control was 'normal' whilst all the others are transparent.
 

Users who are viewing this thread

Top Bottom