Search x two parameters (1 Viewer)

Emma35

Registered User.
Local time
Today, 16:16
Joined
Sep 18, 2012
Messages
455
Hi Guys,
Kind of a two part question. I have a small form which contains three combo boxes. These combo's are used to populate the criteria rows in a query.

1. Is there a way I could get the query to return some results if I only fill in one combo box ? (at the moment I get nothing unless I fill in all three)

2. Is it possible to make two selections from a combo box and get the query to return the results for both selections at the same time ?.

Thanks, Em
 

theDBguy

I’m here to help
Staff member
Local time
Today, 16:16
Joined
Oct 29, 2018
Messages
21,358
Hi Em. For each criteria referencing the combobox, change it from something like this:
Code:
Forms!FormName.ComboboxName
into this:
Code:
Forms!FormName.ComboboxName OR Forms!FormName.ComboboxName Is Null
Hope it helps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 19:16
Joined
Feb 19, 2002
Messages
42,977
The syntax to allow OPTIONAL criteria is:

Where (fldA = Forms!yourform!fldA OR Forms!yourform!fldA Is Null)
AND (fldB = Forms!yourform!fldB OR Forms!yourform!fldB Is Null)
AND (fldC = Forms!yourform!fldC OR Forms!yourform!fldC Is Null)

The sample shows how to use a multi-select list box. I think you want to look at either the third or the fourth menu option.
 

Attachments

  • FillFormFields20180816.zip
    342.4 KB · Views: 24

Emma35

Registered User.
Local time
Today, 16:16
Joined
Sep 18, 2012
Messages
455
Thanks guys that's working great....i did notice however that there are extra rows being added to the criteria section of the query every time i run it ?. is this normal ? (Attached)

Pat.....i liked your sample database and there's some ideas in there i could use in the future but i'm not sure it shows how to query two options from the same listbox ?. Bear with me i'm still learning in some ways !
 

Attachments

  • Capture.PNG
    Capture.PNG
    16.1 KB · Views: 31

Pat Hartman

Super Moderator
Staff member
Local time
Today, 19:16
Joined
Feb 19, 2002
Messages
42,977
I explained with words how to use multiple criteria. The sample shows you how to use a multi-select combo or listbox.
 

Emma35

Registered User.
Local time
Today, 16:16
Joined
Sep 18, 2012
Messages
455
Ok thanks i have the query working now. What about the extra lines in the criteria section ?....will Access just keep adding them every time i use the query ?. Should i go in and clear them off or does it make any difference ?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 19:16
Joined
Feb 19, 2002
Messages
42,977
I'm not sure what you mean. The QBE generally shows a couple of empty criteria lines when you open the query in design view. Is that what you are asking about? Don't worry about extra lines.
 

Emma35

Registered User.
Local time
Today, 16:16
Joined
Sep 18, 2012
Messages
455
I've attached a snapshot of how the query looks in Design View at the moment
 

Attachments

  • Query.PNG
    Query.PNG
    16.9 KB · Views: 25

Users who are viewing this thread

Top Bottom