Recon_Alpha
08-09-2007, 07:41 AM
Ok, here's my problem that I can not figure out. I hope I can explain it right :blush:
1. I have a sub form that I want hidden unless it matches text in a field.
2. The field that I will be using is a Combo Box using a look up to a table. I have 5 different answers that could be selected. Let's call them :
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
So far this is what I have and it works fine. It hides the sub form unless Answer1 is selected.
Private Sub PersonnelType_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If Me.Controls(ctl.Name).Tag = "MyControllName" Then
Me.Controls(ctl.Name).Visible = False
End If
Next ctl
If Me!PersonnelType = "Answer 1" Then
For Each ctl In Me.Controls
If Me.Controls(ctl.Name).Tag = "MyControllName" Then
Me.Controls(ctl.Name).Visible = True
End If
Next ctl
End If
End Sub
However, what I need is the sub-form to be hidden unless Answer1 OR Answer 4 is selected. It will still remain hidden if Answer 2, 3, or 5 is selected but if Answer 1 OR Answer 4 (or more if I want) is selected, it will show the sub-form so I can enter data.
I've tried using Or but like I said, I really don't know VBA to figure out what will work.
Can anyone please lend a helping hand?
Thank you!
1. I have a sub form that I want hidden unless it matches text in a field.
2. The field that I will be using is a Combo Box using a look up to a table. I have 5 different answers that could be selected. Let's call them :
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
So far this is what I have and it works fine. It hides the sub form unless Answer1 is selected.
Private Sub PersonnelType_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If Me.Controls(ctl.Name).Tag = "MyControllName" Then
Me.Controls(ctl.Name).Visible = False
End If
Next ctl
If Me!PersonnelType = "Answer 1" Then
For Each ctl In Me.Controls
If Me.Controls(ctl.Name).Tag = "MyControllName" Then
Me.Controls(ctl.Name).Visible = True
End If
Next ctl
End If
End Sub
However, what I need is the sub-form to be hidden unless Answer1 OR Answer 4 is selected. It will still remain hidden if Answer 2, 3, or 5 is selected but if Answer 1 OR Answer 4 (or more if I want) is selected, it will show the sub-form so I can enter data.
I've tried using Or but like I said, I really don't know VBA to figure out what will work.
Can anyone please lend a helping hand?
Thank you!