Others

Use a TempVar to Control Wildcard Criteria in a Microsoft Access Query

Rana GarciaRana Garcia Nov 14, 2026 869 views

Question details

Use a TempVar to switch an Access query between records where a field equals 1 and all records.

Use a TempVar to Control Query Criteria in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
A query should filter a column to 1 when the AccountStatus TempVar is 1, and return all records when the TempVar has another value.
Observed behavior
The query needs criteria that apply the filter only for the specified TempVar value.
Before you start

Confirm that the AccountStatus TempVar is set before running the query and identify the field to filter. The examples assume AccountStatus contains a non-Null numeric value.

Solution 1Recommended

Use Boolean conditions in the Access query

Use this approach to return all records, including rows with a Null field value, when AccountStatus is not 1.

1
Open the query in SQL View

In Access, right-click the query in the Navigation Pane, select Design View, and switch to SQL View.

2
Add the condition

Add this condition to the WHERE clause, replacing YourColumn with the field name: (([YourColumn] = 1 AND [TempVars]![AccountStatus] = 1) OR [TempVars]![AccountStatus] <> 1). If the query already has a WHERE clause, combine this condition with the existing criteria using AND rather than adding a second WHERE.

3
Test both values

Set AccountStatus to 1 and run the query to check that only matching records appear. Then set it to another non-Null value and run the query again to check that all records appear.

Use Boolean conditions in the Access query
Null TempVar values: A Null AccountStatus value does not satisfy either comparison. If Null should also return all records, add OR [TempVars]![AccountStatus] Is Null inside the grouped condition.
Free Microsoft Office alternative

Review exported Access data in WPS Spreadsheets

WPS Office is a free, lightweight alternative for working with Office files. Export Access results to a spreadsheet to review and filter them in a familiar interface; WPS does not run Access TempVar queries.

Filter exported query results in WPS SpreadsheetsOpen and edit Microsoft Excel XLSX filesUse a familiar interface for an easier transition from Microsoft OfficeWork with a free, lightweight office suite
QA img-9

Frequently Asked Questions

Where do I enter the TempVar criteria in Access?

For the Like expression, open the query in Design View and enter it in the Criteria row under the field. For the Boolean condition, switch to SQL View and add it to the WHERE clause.

Why does Like "*" leave out some records?

The wildcard does not match Null field values. Use the Boolean condition to include those records when AccountStatus is not 1.

What happens if AccountStatus is Null?

The comparisons to 1 and not equal to 1 do not evaluate as true. To return all records in that case, add OR [TempVars]![AccountStatus] Is Null inside the grouped WHERE condition.

Can WPS Office run an Access query that uses TempVars?

No. Run the TempVar query in Microsoft Access, then export its results to an Excel file if you want to review or filter them in WPS Spreadsheets.