Hello!
I am trying to hide 2 comboboxes in a form.
I have 3 comboboxes on a form. "ComboboxOptions", "ComboboxSubOption1" and "ComboboxSubOption2".
"ComboboxOptions" has 3 values. "All", "Cat", and "Dog". "ComboboxOptions" is always supposed to remain visible.
When "ComboboxOptions" = "All", I would like for the other two comboboxes to be hidden.
When "ComboboxOptions" = "Cat", I would like "ComboboxSubOption1" to be visible (in additional to "ComboboxOptions").
When "ComboboxOptions" = "Dog", I would like "ComboboxSubOption2" to be visible (in additional to "ComboboxOptions").
When you change between "All", "Cat", and "Dog", the comboboxes should appear and disappear as described above.
I have been able to get some what close to what I am after. By default, "ComboboxOptions" is set to "All", so I have set "Visible" to "No" in the propertysheets of "ComboboxSubOption1" and "ComboboxSubOption2".
I then right clicked on "ComboboxOptions" and went to "build event", then "code builder".
I have the following code:
Code:
Private Sub ComboboxOptions_AfterUpdate()
If Me.ComboboxOptions = "All" Then
Me.ComboboxSubOption1.Visible = False
Else
Me.ComboboxSubOption1.Visible = True
End If
End Sub
This sort of works for what I am trying to accomplish. When the form is first loaded, the suboption comboboxes are already hidden. When I change "ComboboxOptions" to anything other than "All", "ComboboxSubOption1" becomes visible.; however, if I change it back to "All", it does not become hidden again for some reason.
This leaves me with 3 problems:
1) Right now, "ComboboxSubOption1" shows whether I select "Cat" or "Dog", when it should only show if I select "Cat". Do I need to add in an Else If f some kind? I tried to add one in, but it gave an error.
2) How do I make sure that the rules stay in place the entire time? If I change the "ComboboxOptions" more then once, the rules need to still take effect.
3) How do I add in code for my second Suboption combobox? Do I just add another section that starts with Private Sub ComboboxOptions_AfterUpdate()?
Thank you for any help that you can provide!
James