Run the query

When you are ready to run an action query, double-click it in the Navigation Pane, or click it and then press ENTER.

Important: By default, Access disables all action queries in a database unless you indicate that you trust the database. You can indicate that you trust a database by using the Message Bar, just below the Ribbon.

Trust a database

  1. On the Message Bar, click Options.
    The Microsoft Office Security Options dialog box appears.
  2. Select Enable this content and then click OK.

Run a parameter query

A parameter query prompts you for a value when you run it. When you supply the value, the parameter query applies it as a field criterion. Which field it applies the criterion to is specified in the query design. If you do not supply a value when prompted, the parameter query interprets your input as an empty string.

A parameter query is always also another type of query. Most parameter queries are select queries or crosstab queries, but append, make-table, and update queries can also be parameter queries.

You run a parameter query according to its other query type, but, in general, use the following procedure.

Run the query

  1. Locate the query in the Navigation Pane.
  2. Do one of the following:
  3. When the parameter prompt appears, enter a value to apply as a criterion.

Run a SQL-specific query

There are three main types of SQL-specific query: union queries, pass-through queries, and xmlns:friendlytitlelookup='urn:FriendlyTitleLookup' xmlns:hrefappend='urn:HrefExtensions'>Union queries combine data from two or more tables, but not in the same manner as other queries. Whereas most queries combine data by concatenating rows, union queries combine data by appending rows. Union queries differ from append queries in that union queries do not change the underlying tables. Union queries append the rows in a recordset that does not persist after the query is closed.

Pass-through queries are not processed by the database engine that comes with Access; rather, they are passed directly to a remote database server that does the processing and then passes the results back to Access.

Data-definition queries are a special type of query that does not process data; instead, xmlns:friendlytitlelookup='urn:FriendlyTitleLookup' xmlns:hrefappend='urn:HrefExtensions'>SQL-specific queries cannot be opened in Design view. They can only be opened in SQL view, or run. Except for xmlns:antixss='urn:AntiXSSExtensions' xmlns:friendlytitlelookup='urn:FriendlyTitleLookup' xmlns:hrefappend='urn:HrefExtensions'>

Locate the query in the Navigation Pane.
Do one of the following:

Troubleshoot an error message

The following table shows some common error messages you may encounter. These errors can appear either as a message in a cell (instead of an expected value), or as an error message. The sections that follow the list include procedures you can use to resolve these errors.

Note: This content of this table is not exhaustive. If it does not include the error message you received, you can submit feedback by using the form at the end of this article and including specific information about the error message in the comment box provided.
Error message
Problem
Solution
Type mismatch in expression
The query may be joining fields that have different data types.
Check the query design and ensure that the joined fields have the same data type. For instructions, see the section Check the joined fields in your query.
Record is Deleted
This can occur if either the object or the database is damaged.
Compact and repair the database. For instructions, see the section Compact and repair your database.
Circular reference caused by alias
The alias assigned to a field is the same as a component of the expression for that field.
An alias is a name that is given to any expression in the Field row of the query design grid that is not an actual field. Access assigns the alias for you if you do not do so yourself; for example, EXPR1. An alias is immediately followed by a colon (:) and then by the expression. When you run the query, the alias becomes the column name in the datasheet.
Change the alias. For instructions, see the section Change a field alias.
#Error
This error can occur when the value of a calculated field is greater than the value allowed by the field's FieldSize property setting. This also occurs when the denominator of a calculated field is or evaluates to zero (0).
Ensure that the calculated field's denominator does not evaluate to zero (0). If appropriate, change the FieldSize property.
#Deleted
The record being referred to has been deleted.
If the record was deleted accidentally, it must be restored from a backup. If the deletion was intentional, you can dismiss this error message by pressing SHIFT+F9 to refresh the query.

Check the joined fields in your query

To check the data types of fields in a query, you look at the source tables in Design view and inspect the properties for the fields you are checking.

  1. Open the query in Design view. Joins appear as lines that connect fields in the source tables. Note the table and field names for each join.
  2. In the Navigation Pane, right-click each table that has one or more fields joined in your query, and then click Design View.
    1. Joined fields with different data types.
    2. Right-click the table, then click Design View.
  3. For each join, compare the values in the Data Type column of the table design grid for the fields involved in that join.
    1. Check the data type of the joined fields in table Design view.
  4. To switch to a table so that you can see its fields, click the tab with that table's name.

Compact and repair your database

Running the Compact and Repair Database utility within Access can improve the performance of your database. This utility makes a copy of the database file and, if it is fragmented, rearranges how the database file is stored on disk. After the compact and repair process has completed, the compacted database will have reclaimed wasted space, and is usually smaller than the original. By compacting the database frequently, you can help ensure optimal performance of the database application, and also resolve errors that arise from hardware problems, power failures or surges, and similar causes.

After the compact operation has completed, query speed is enhanced because the underlying data has been rewritten to the tables in contiguous pages. Scanning contiguous pages is much faster than scanning fragmented pages. Queries are also optimized after each database compaction.

During the compact operation, you can use the original name for the compacted database file, or you can use a different name to create a separate file. If you use the same name and the database is compacted successfully, Access automatically replaces the original file with the compacted version.

Set an option that automates this process

  1. Click File > Options to open the Access Options dialog box.
  2. Click Current Database and, under Application Options, select the Compact on Close check box.
    This causes Access to automatically compact and repair the database every time it is closed.

Manually compact and repair your database

  1. Click Database Tools > Compact and Repair Database.

Change a field alias

  1. Open the query in Design view.
  2. In the query design grid, look for fields that have aliases. These will have a colon at the end of the field name, as in Name:.
  3. Check each alias to ensure that the alias does not match the name of any field that is part of the alias' expression. If it does, change the alias.