Applying Filter

C

Casey Howlett

Could someone please show me a syntax example of applying a filter to a
table in a sub-procedure using the DoCmd.OpenForm and does it matter if the
field that I am trying to filter is an "AutoNumber" Field. I have Tried
everything including using a query for my data source, but no luck.

TIA
Casey Howlett
 
V

Van T. Dinh

There are various ways you can restrict the RecordSource of the Forms such
as:

1. You can use a Query with some criteria as the RecordSource for the Form.
For example, I may have the "Query1" with the SQL String:

SELECT *
FROM MyTable
WHERE RecordID >= 100
as the RecordSource for my Form

2. If you use the OpenForm Method, you can use the [FilterName] argument of
the OpenForm Method to restrict the RecordSource. For example, if I want to
open "Form1" based on MyTable but restrict to Records with RecordID >= 100
(i.e. same condition as "Query1" above), I can use:

DoCmd.OpenForm "Form1", , "Query1"

and the OpenForm Method will use the criteria in the Query to limit the
Records.

3. You can also use the [WhereCondition] argument of the OpenForm Method.
For example (same as 2):

DoCmd.OpenForm "Form1", , , "[RecordID] >= 100"

4. You can also use the Properties "Filter" and "FilterOn" of the Form to
limit the number of Records in the design of the Forms or even use VBA code
to set these after you open the Form.

An AutoNumber Field doesn't make any difference.

Check Access VB Help on the Keywords I mentioned above.
 

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