How do I hide controls until conditions are met?

  • Thread starter Thread starter CCB
  • Start date Start date
C

CCB

I have controls that I want hidden until a specific value is selected in a
value list.

There are two values in the value list and depending on which is selected, I
want different controls displayed. What's the best way to accomplish this?
 
CCB said:
I have controls that I want hidden until a specific value is selected
in a value list.

There are two values in the value list and depending on which is
selected, I want different controls displayed. What's the best way to
accomplish this?

In the AfterUpdate of the (assume you mean a ListBox)...

Select Case Me.ListBoxName
Case "SomeValue"
Me.Control_1.Visible = True
Me.Control_2.Visible = False
Case "SomeOtherValue"
Me.Control_1.Visible = False
Me.Control_2.Visible = True
End Select
 
On the form_open event I would set
Me.Control_1.Visible = False
Me.Control_2.Visible = False

Then use Rick's code

Allan Murphy
Email: (e-mail address removed)
 
Sorry I'm so ignorant on this. Can I do this as an expression? Also, where
you have Control_1.Visible, I change this to my field name? Thanks for all
the help so far.
 
CCB said:
Sorry I'm so ignorant on this. Can I do this as an expression? Also,
where you have Control_1.Visible, I change this to my field name?
Thanks for all the help so far.

What you want to do requires running code or a macro in response to the
"events" on the form. Obviously you would substitute the generic sample
names we often use in these groups with the actual names of your objects.

In your case you need to respond to at least two events. The Current event
of the form fires as you arrive at each record. The AfterUpdate event of
your ListBox fires every time you make a selection from the list.

You need to use those events to set the Visible property of your controls
and it will take either VBA code or a Macro to do that. Most people in here
use VBA so you are most likley to get suggestions that do so as well.
 
What has been suggested would be an event rather than an expression. To add
the suggested code to the After Update event of the list box, make sure the
form is open in design view, then open the list box's property sheet (right
click the list box and select Properties is one way). Click the Event tab.
Click After Update. An arrow and three dots will appear on the right side of
the After Update line. Click the three dots. Click Code Builder, then OK.
Insert the code between Private Sub (etc.) and End Sub. As has been
mentioned, substitute the actual name of your list box and other details
(such as Case "SomeValue", where instead of "SomeValue" you would but the
actual text from your list box). The code and procedure for adding it would
be the same for a combo box. To add code to the form, right click the square
at the very top left of the form, about where the rulers meet, and select
Properties. Proceed as with the list box.
 
Back
Top