Automatic combo box values on a form

G

Guest

I apologize in advance since I do not know the proper terminology involved or
else I would search myself. I presume this topic is covered here somewhere.

A form I designed selects query criteria using combo boxes. When I select a
value from one combo box, how can I get the relevant values in another combo
box based on my selection?

For instance, I select "David" from the FirstName combo box. As soon as I
select this value, the LastName combo box would then return all Last Names
where the person's First Name is David. I guess this acts like an additional
query of sorts.

Many websites implement this technique, I would like to do it with Access.
Thank you for your help.
 
J

John Vinson

I apologize in advance since I do not know the proper terminology involved or
else I would search myself. I presume this topic is covered here somewhere.

A form I designed selects query criteria using combo boxes. When I select a
value from one combo box, how can I get the relevant values in another combo
box based on my selection?

For instance, I select "David" from the FirstName combo box. As soon as I
select this value, the LastName combo box would then return all Last Names
where the person's First Name is David. I guess this acts like an additional
query of sorts.

Many websites implement this technique, I would like to do it with Access.
Thank you for your help.

This is easily handled by basing the second combo box on a Query
referencing the first combo box. Let's say your form is named
frmMyForm, with combo boxes cboFirstName and cboLastName.

The query upon which cboLastName is based could use

=[Forms]![frmMyForm]![cboFirstName] OR
[Forms]![frmMyForm]![cboFirstName] IS NULL

as a criterion on the FirstName field in the table. If there is no
first name selected it will show all last names; if there is, it will
show only those last names for that firstname.

You will need one line of VBA code: in the AfterUpdate event of
cboFirstName,

Private Sub cboFirstName_AfterUpdate(Cancel as Integer)
Me!cboLastName.Requery
End Sub

This will alert the last name combo that its data source has changed.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Combo Box 2
Combo Box 3
Combo Box Problems 1
Combo Box Help 7
Combo Box Question 4
Combo Box QUESTION 5
POPULATE a textbox based on combo box selection 3
form combo box question 4

Top