Blank Combo Box Filters

M

Matt

I have two combo boxes on a form to select Region and Customer. If the
Region is selected (e.g. North America), but a customer is not, I want all
the records to come back for that region regardless of customer.

If the customer is selected (e.g. Dell), but a region is not, I want all the
records to come back for the customer selected regardless of region.

And then if a Region and Customer is selected, I want it to display the
records that match both selections.

How would I go about doing this? Do I need to write code to make this
happen? Thanks in advance for your help.

The table I'm referencing has a primary key on Product, Region, and
Customer.
 
K

KARL DEWEY

Try this --
SELECT Product, Region, Customer
FROM YourTable
WHERE ([Region] = [Forms]![YourFormName]![cboRegion] OR
[Forms]![YourFormName]![cboRegion] Is Null) AND ([Customer] =
[Forms]![YourFormName]![cboCustomer] OR [Forms]![YourFormName]![cboCustomer]
Is Null);
 
M

Matt

Hi Karl,

Thanks for the help. It works! But the problem I run into is when I try to
select another region or customer from the drop down box, the results don't
come up. I just get blank records. I have to close the form and then
re-open it before the correct results will come up.

How do I fix that?

Thanks,
Matt


KARL DEWEY said:
Try this --
SELECT Product, Region, Customer
FROM YourTable
WHERE ([Region] = [Forms]![YourFormName]![cboRegion] OR
[Forms]![YourFormName]![cboRegion] Is Null) AND ([Customer] =
[Forms]![YourFormName]![cboCustomer] OR [Forms]![YourFormName]![cboCustomer]
Is Null);

--
Build a little, test a little.


Matt said:
I have two combo boxes on a form to select Region and Customer. If the
Region is selected (e.g. North America), but a customer is not, I want all
the records to come back for that region regardless of customer.

If the customer is selected (e.g. Dell), but a region is not, I want all the
records to come back for the customer selected regardless of region.

And then if a Region and Customer is selected, I want it to display the
records that match both selections.

How would I go about doing this? Do I need to write code to make this
happen? Thanks in advance for your help.

The table I'm referencing has a primary key on Product, Region, and
Customer.
 

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