Setting rowsource for Combo Box

  • Thread starter Thread starter rick.bresin
  • Start date Start date
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.
 
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.
 
Thanks Dirk,

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