How to: populate a subform based on 2 list box selections

K

Kurt

I think my question is how to create a SEARCH form that
will display results of 2 or more search criteria.

Example:

I have a form with 2 list boxes and a subform. The first
list box is based on a query showing unique OWNER names.
The second list box is based on another query showing
unique CAR types.

I would like the user of the form to select an owner name
from listbox #1 AND then choose a car name from
listbox#2, click on a button andthe subform will populate
all entries where the owner and car match the users
selections. I assume I must use VBA for this?

Any help would be appreciated.
 
T

tina

on the main form's command button, try adding the following code to the
procedure:

With Me!SubformControlName.Form
.Filter = "OwnerName = " & Forms!MainFormName!OwnerListBoxName & "
And CarType = " & Forms!MainFormName!CarListBoxName
.FilterOn = True
End With

that should work for number values in the listboxes. if a value is text, add
single quotes inside the double quotes. example: CarType is a text value,
not a number.

.Filter = "OwnerName = " & Forms!MainFormName!OwnerListBoxName & "
And CarType = '" & Forms!MainFormName!CarListBoxName & "'"

make sure you reference the subform control name, not the name of the
subform object as it shows in the database window.

hth
 
T

Treena

GREAT JOB! Thank, this works. It took me a while to
figure out the text fields and use of the ', but it
finally works. Thank Goodness for these forums and
people like you who take the time to answer questions.

Treena
 

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

Top