ctl.Tag Loop

J

Jacco

Hi everyone,
I want to create a loop where a form is validated. If the leave a field
Empty then I want the label to become bold letters Field and label are named
logically: [Date] & [Date_Label]

I thought this would do the trick, but it doesn't:

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "required" Then
If Nz(ctl.Value, 0) = 0 Then
ctl_label = "[" + ctl.Name + "_Label]"
ctl_label.FontWeight = 600
End If
End If
Next ctl

Any suggestions in how to do this without writing a line for every Field?
Jacco
 
S

Sprinks

Hi, Jacco.

One good way to do this is using the Parent property of the label control,
which returns the control to which the label is attached:

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
If Nz(ctl.Parent.Value, 0) = 0 Then
ctl.FontWeight = 600
End If
End If
Next ctl

Hope that helps.
Sprinks
 
Top