Putting 2 Codes Together

D

DS

Is This How You Do This?

For Each ctl In Me.Controls
If ctl.Tag = "1" Then
ctl.Visible = True
End If
Next ctl
For Each ctl In Me.Controls
If ctl.Tag = "2" Then
ctl.Visible = True
End If
Next ctl

Or Can You Do it This Way....

For Each ctl In Me.Controls
If ctl.Tag = "1" and "2" Then
ctl.Visible = True
End If
Next ctl

Thanks
DS
 
R

rkc

DS said:
Is This How You Do This?

For Each ctl In Me.Controls
If ctl.Tag = "1" Then
ctl.Visible = True
End If
Next ctl
For Each ctl In Me.Controls
If ctl.Tag = "2" Then
ctl.Visible = True
End If
Next ctl

Or Can You Do it This Way....

For Each ctl In Me.Controls
If ctl.Tag = "1" and "2" Then
ctl.Visible = True
End If
Next ctl

The clearest way is to put them in seperate if statements.
No need to loop through the controls twice.

For Each ctl In Me.Controls
If ctl.Tag = "1" Then
ctl.Visible = True
End If

If ctl.Tag = "2" Then
ctl.Visible = True
End If
Next ctl
 
G

Graham R Seach

This is a simple way:
For Each ctl In Me.Controls
ctl.Visible = (ctl.Tag = "1" Or ctl.Tag = "2")
Next ctl

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
D

DS

rkc said:
The clearest way is to put them in seperate if statements.
No need to loop through the controls twice.

For Each ctl In Me.Controls
If ctl.Tag = "1" Then
ctl.Visible = True
End If

If ctl.Tag = "2" Then
ctl.Visible = True
End If
Next ctl
Thanks, Its Cleaner!
DS
 
D

DS

Graham said:
This is a simple way:
For Each ctl In Me.Controls
ctl.Visible = (ctl.Tag = "1" Or ctl.Tag = "2")
Next ctl

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Even Cleaner!!!
Thanks
DS
 
Top