totn Access

MS Access 2003: Filter a query based on a text box value

This MSAccess tutorial explains how to filter a query based on a text box value in Access 2003 (with screenshots and step-by-step instructions).

Question: I have an Access 2003/XP/2000/97 database that contains a form called Orders. I want to be able to create a query that returns the currently selected record from the Orders form. How can I do this?

Answer: One way to write your query is to include a reference to the text box (or other object) that contains the value that you want to use as a query filter.

In the example below, we only want to return the rows where the OrderID matches the textbox called OrderID in the Orders form.

Microsoft Access

As you can see, we've placed the following reference in the query.

[Forms]![Orders]![OrderID]

We'll quickly explain this reference.

[Forms]![Orders] refers to the form called "Orders".

[OrderID] is the name of the text box that we want to use as a filter in the query.

The only drawback to this solution is that if the Order form is not currently loaded and you run the query above, the following window will appear.

Microsoft Access

Because the query can not find the Orders form, it will query you for a parameter. You can enter the appropriate OrderID value and click on the OK button.