Setting rowsource for Combo Box

R

rick.bresin

I'm using the following rowsource query to filter a combobox

SELECT Products.ProductID, Products.ProductName, Products.PartNumber,
Products.UnitPrice, Products.ModelNum
FROM Products
WHERE (((Products.ModelName)=[Model]));

Model is textbox on the form

This works fine to filter the list to a specific Model but if the
Model is Null the combo box shows no records. How can I alter the
rowsource to still filter according to model name but show all products
if Model textbox is null?

Is It better to set rowsource in code somewhere or would it be better
for me to learn how to create a filter for this subform?

I've searched the group but haven't found anything that quite applies.
 
D

Dirk Goldgar

I'm using the following rowsource query to filter a combobox

SELECT Products.ProductID, Products.ProductName, Products.PartNumber,
Products.UnitPrice, Products.ModelNum
FROM Products
WHERE (((Products.ModelName)=[Model]));

Model is textbox on the form

This works fine to filter the list to a specific Model but if the
Model is Null the combo box shows no records. How can I alter the
rowsource to still filter according to model name but show all
products if Model textbox is null?

You could try this:

SELECT ProductID, ProductName, PartNumber, UnitPrice, ModelNum
FROM Products
WHERE (ModelName=[Model]) OR ([Model] Is Null);

I'm not sure whether it might not be a good idea to fully qualify the
reference to the [Model] text box, but if it works as it is, fine.
 
R

rick.bresin

Thanks Dirk,

Your answer is much appreciated. It works just as needed.
I can't believe how often the answer is so simple.
 

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