How to use a combo box to filter a forms data

tmd63

Hobbyist relational database creator
Local time
Today, 09:32
Joined
Oct 26, 2016
Messages
22
I have a table that has a Part Number field. I wish to filter a form by using a combo box. I want to have the combo box display the part number of the entry and then filter the item using the part number, adding either <All> and <NEW> to the list to allow selection.
Is this possible? Or do I have to use a separate Part field?
 
You would need an unbound combo.
Use a union query to add your extra values All being 0 Autonumber
Then in the AfterUpdate event of the combo set the filter accordingly.
 
You could start with using the combobox wizard and selecting the third option. I would suggest using two separate buttons to clear the filter (All option) and going to a new record (New option).
 
This solution on my website might be a bit too comprehensive, but it might give you some ideas of how to go about it..

There is a nice little function, which you might be able to employ....

 
I bind my forms to queries that reference the combo:
Select ...
From ...
Where (MyField = Forms!MyForm!cboMyField OR Forms!MyForm!cboMyField Is Null) Or (MyDate > IIf(Forms!MyForm!NewOnly = True, Date() - 7, #1/1/1900#)

The "OR" part of the first clause handles the "all" part so I don't add anything to the combo. The second clause handles the "new" requirement. I'm assuming a checkbox and hard coded dates. 1/1/1900 seems old enough but use what makes sense. Date() -7 seems new enough but use what makes sense.

Since there is more than one field to consider, I add a search button. In the click event of the search button. I use:
Me.Requery

The form will open to the "all" option since that seems to be what you want. If your BE is SQL Server, this is inefficient so let us know and someone will adjust the criteria so the form opens empty instead.
 

Users who are viewing this thread

Back
Top Bottom