change subform label backcolors function

T

ToniS

I have a function to change the forms labels backcolor.
The function works fine for all forms except for sub forms.
When the subform is ran by itself the label colors change correctly.
As soon as I run the main form with the subforms on it, the main form
colors change fine but the subform label colors do not change.
I call the function with in the open event of each form.
Any ideas on what I need to do to get it to work?

I call the ChangeLabelColor in the main and subform open event.

Below is my source code example for the subform

Private Sub Form_Open(Cancel As Integer)

ChangeLabelColor Me ' tmhx

strSQL = "SELECT ....."

Form_subfrm_DealerDealerPersons.RecordSource = strSQL

End Sub


Function ChangeLabelColor(formname As Form)

Dim ctrl As Control

On Error Resume Next

For Each ctrl In Forms(formname.Name).Controls
If (TypeOf ctrl Is Label) Then
ctrl.BackColor = pubLabelColor
End If
Next ctrl

End Function


Thanks
ToniS
 
S

Sylvain Lafontaine

It's because subforms are not part of the forms collection. Use the
following line instead:

Function ChangeLabelColor(formname As Form)
...
For Each ctrl In formname.Controls
...
 

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