PDA

View Full Version : Hide a sub-form based off selections from a combo box



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!

qff
08-09-2007, 08:18 AM
Hi

I think OR should work as below

If Me!PersonnelType = "Answer 1" OR Me!PersonnelType = "Answer 4"

regards
qff

Recon_Alpha
08-09-2007, 11:02 AM
Yep, that worked.

That's strange, I thought I tried that but I must have put

If Me!PersonnelType = "Answer 1" OR If Me!PersonnelType = "Answer 4"

Thanks for your help!