How do I make a combobox appear on a form conditionally

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a "nature" combobox.
I want to have different comboboxes appear based on the selection in the
"nature" combobox.
I suspect, I need to have an "after update" macro for the "nature" combobox
that has a series of if-then statements.
If that is even the right approach, I have no idea how to create a statement
that would say something like, if "meeting" is selected in nature.combobox,
then make "attendees.combobox" visible."

I hope that makes sense.

TIA
Papa
 
Papa said:
I have a form with a "nature" combobox.
I want to have different comboboxes appear based on the selection in
the "nature" combobox.
I suspect, I need to have an "after update" macro for the "nature"
combobox that has a series of if-then statements.
If that is even the right approach, I have no idea how to create a
statement that would say something like, if "meeting" is selected in
nature.combobox, then make "attendees.combobox" visible."

I hope that makes sense.

TIA
Papa


'(lines here to first make all ComboBoxes not visible)
Me.attendees.Visible = False
Me.SomeOtherCbo = False
etc..

'(now a case statement to make one ComboBox visible)
Select Case Me.nature
Case "meeting"
Me.attendees.Visible = True
Case "SomeOtherValue"
Me.SomeOtherCbo.Visible = True
etc..
End Select
 
Rick,
This looks pretty straightforward. I appreciate your parenthiticals.
But where do I put this code? In the open form? After update?
My guess is the first code in the open form, and the other in after update
for the combobox.
Am I warm?
 
Papa said:
Rick,
This looks pretty straightforward. I appreciate your parenthiticals.
But where do I put this code? In the open form? After update?
My guess is the first code in the open form, and the other in after
update for the combobox.
Am I warm?

Fairly. You would actually want it in the Current event of the form to
accomodate record navigation and in the AfterUpdate of the ComboBox to
accomodate changes there.
 
Ok
Here is what I have for the on current for the form:
Private Sub Form_Current()
Me.cboStation.Visible = False
End Sub

Here is what I have for the afterupdate for the combobox:
Private Sub CallNature_AfterUpdate()
Select Case Me.CallNature
Case "station visit"
Me.cboStation.Visible = True
'Case "SomeOtherValue"
'Me.SomeOtherCbo.Visible = True
End Select
End Sub

Sure enough, the dependent cbo is not visible. And it doesn't seem to want
to become visible - I'm doing something wrong.
 
Papa said:
Ok
Here is what I have for the on current for the form:
Private Sub Form_Current()
Me.cboStation.Visible = False
End Sub

If you navigate to an existing record where CallNature is already set to
"station visit" then don't you want the cboStation to be visible? If so you
need ALL of your AfterUpdate code copied into the Current event (or just
call that sub from the Current event).
Here is what I have for the afterupdate for the combobox:
Private Sub CallNature_AfterUpdate()
Select Case Me.CallNature
Case "station visit"
Me.cboStation.Visible = True
'Case "SomeOtherValue"
'Me.SomeOtherCbo.Visible = True
End Select
End Sub

Sure enough, the dependent cbo is not visible. And it doesn't seem
to want to become visible - I'm doing something wrong.

Are you sure that the VALUE of your first ComboBox is "station visit"? If it
shows one thing while storing another (common with ComboBoxes) then you need
to test for the bound value rather than the text that you see.
 
Back
Top