Use a TempVar to Control Wildcard Criteria in a Microsoft Access Query
Question details
Use a TempVar to switch an Access query between records where a field equals 1 and all records.

- 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.
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.
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.
In Access, right-click the query in the Navigation Pane, select Design View, and switch to SQL View.
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.
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.

Place a Like expression in the field's query criteria
Use this shorter expression when a wildcard comparison is suitable for the field and excluding Null field values is acceptable.
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.

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.




