Displaying input fields based on a combo box selection

  • Thread starter Thread starter ace
  • Start date Start date
A

ace

Can anyone explain how you can show specific set of fields on a form
depending on the selection from, from example, a combo box!

For example, if "A" is selected from a combo box, form shows fields "Name"
and "eMail" and shows "Name" and "Phone" if "B" is selected. Like dynamicly
change the form!

Thanks,
AC Erdal
 
Hi ace,
one straightforward way is to use a select case statement.
In the after update of the combo put code like-->
Select case Me.NameOfCombo
Case "A"
me.txtName.visible = True
Me.txtEmail.visible = true
Me.txtPhone.visible = false

Case "B"
Me.txtName.visible = True
Me.txtemail.visible = false
Me.txtphone.visible = true

Case else

End Select

You would also need this code in the current event of the form.


If you only have a few choices, the above is feasible.
Another option is to use a table to store names of which fields are visible
for which values of the combo.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Jeannette,

I just want to clarify that the me.txtname.visible statment is for text box.
However, if I have an another combo box orany other control box in my form, I
can still make them visible or non-visible! Can you give an example if it is
for example a combo box that I want to make it non-visible! Also, I assume
by default everything is visible and I just need to make them non-visible
when I need to!

When you are talking about needing this code in the current event of the
form, I presume you mean the "On Current" event field" of the form's property
field! Is that correct? Can you also explain why do you need this code there
as well!

Thanks,
AC Erdal
 
For a combo, list box and checkbox, see below.
Me.NameOfCombo.Visible = True - make it visible
Me.NameOfCombo.Visible = False - hide it

Me.NameOfListbox.Visible = True - make it visible
Me.NameOfListbox.Visible = True - hide it

Me.NameOfCheckBox.Visible = True
Me.NameOfCheckBox.Visible = false

You can set some of all of the controls to hidden using the property sheet.
Those controls will be hidden when the form opens, but will become visible
when you use code like Me.NameOfControl.Visible = True

You need to use the On Current event for the form when you are opening the
form at an existing record and if you want only the relevant controls
visible depending on whether this record has a fax or and email.

The On Current event runs every time you move to a different or new record,
so this is where access checks to see which controls need to be hidden or
made visible.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Yes, that is correct.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Back
Top