Create tables from the results of a pass-through query (MDB)

 Note   The information in this topic applies only to a Microsoft Access database (.mdb).

  1. Create a pass-through query (pass-through query: An SQL-specific query you use to send commands directly to an ODBC database server. By using pass-through queries, you work directly with the tables on the server instead of the data being processed by the Access database engine.).

ShowHow?

  1. In the Database window (Database window: In Access 2003 and earlier, the window that appears when a database or project is opened. It displays shortcuts for creating new database objects and opening existing objects. In later versions, it is replaced by the Navigation Pane.), click Queries Button image under Objects, and then click New on the Database window toolbar.
  2. In the New Query dialog box, click Design View, and then click OK.
  3. Without adding tables or queries, click Close in the Show Table dialog box.
  4. On the Query menu, point to SQL Specific, and then click Pass-Through.
  5. On the toolbar, click Properties Button image to display the query property sheet.
  6. In the query property sheet, set the ODBCConnectStr property to specify information on the database to which you want to connect. You can type the connection information, or click Build Button image, and then enter information about the server you're connecting to.

When you are prompted to save the password in the connection string, select Yes if you want the password and logon stored in the connection string information.

  1. If the query isn't the type that returns records, set the ReturnsRecords property to No.
  2. In the SQL Pass-Through Query window, type your pass-through query (pass-through query: An SQL-specific query you use to send commands directly to an ODBC database server. By using pass-through queries, you work directly with the tables on the server instead of the data being processed by the Access database engine.).

For details on the syntax for your query, see the documentation for the SQL database server to which you're sending the query.

  1. To run the query, click Run Button image on the toolbar. (For a pass-through query that returns records, you can click View Button image on the toolbar, instead.)

If necessary, Microsoft Access prompts you for information about your SQL server database.

 Notes 

  • If you don't specify a connection string in the ODBCConnectStr property, or if you delete an existing string, Access uses the default string "ODBC;". With this setting, Access prompts you for connection information each time you run the query.
  • Some pass-through queries can return messages in addition to data. If you set the query's LogMessages property to Yes, Access creates a table that contains any returned messages. The table name is the user name concatenated with a hyphen (-) and a sequential number starting at 00. For example, the default user name is ADMIN so the tables returned would be named "ADMIN - 00," "ADMIN - 01," and so on.
  1. Create a make-table query (make-table query: A query (SQL statement) that creates a new table and then creates records (rows) in that table by copying records from an existing table or query result.) based on the pass-through query.

ShowHow?

  1. Create a query, selecting the tables or queries that contain the records you want to put in the new table.

ShowHow?

  1. In the Database window (Database window: In Access 2003 and earlier, the window that appears when a database or project is opened. It displays shortcuts for creating new database objects and opening existing objects. In later versions, it is replaced by the Navigation Pane.), click Queries Button image under Objects, and then click New on the Database window toolbar.
  2. In the New Query dialog box, click Design View, and then click OK.
  3. In the Show Table dialog box, click the tab that lists the tables or queries whose data you want to work with.
  4. Double-click the name of each object you want to add to the query, and then click Close.
  5. Add fields to the Field row in the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.), and if you want, specify criteria (criteria: Conditions you specify to limit which records are included in the result set of a query or filter.) and a sort order.
  6. To view the query's results, click View Button image on the toolbar.
  1. In query Design view (Design view: A view that shows the design of these database objects: tables, queries, forms, reports, and macros. In Design view, you can create new database objects and modify the design of existing objects.), click the arrow next to Query Type Button image on the toolbar (toolbar: A bar with buttons and options that you use to carry out commands. To display a toolbar, press ALT and then SHIFT+F10.), and then click Make Table. The Make Table dialog box appears.
  2. In the Table Name box, enter the name of the table you want to create or replace.
  3. Do one of the following:

Click Current Database.

Click Another Database, and then either type the path of the database where you want to put the new table or click Browse to locate the database.

  1. Click OK.
  2. Drag from the field list (field list: A window that lists all the fields in the underlying record source or database object, except in data access page Design view. In data access page Design view, it lists all the record sources and their fields in the underlying database.) to the query design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.) the fields you want in the new table.
  3. In the Criteria cell for the fields that you've dragged to the grid, type the criteria (criteria: Conditions you specify to limit which records are included in the result set of a query or filter.).
  4. To preview the new table before you create it, click View Button image on the toolbar. To return to query Design view and make changes or run the query, click View Button image on the toolbar again.
  5. To create the new table, click Run Button image on the toolbar.

 Note   The data in the new table you create does not inherit the field properties or the primary key (primary key: One or more fields (columns) whose values uniquely identify each record in a table. A primary key cannot allow Null values and must always have a unique index. A primary key is used to relate a table to foreign keys in other tables.) setting from the original table.

  1. In the make-table query, include all fields from the pass-through query by dragging the asterisk (*) to the design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.).
  2. Run the make-table query.

ShowHow?

Do one of the following:

ShowRun a select or crosstab query

ShowRun an action query

Unlike select (select query: A query that asks a question about the data stored in your tables and returns a result set in the form of a datasheet, without changing the data.) and crosstab queries (crosstab query: A query that calculates a sum, average, count, or other type of total on records, and then groups the result by two types of information: one down the left side of the datasheet and the other across the top.), you can't view the results of an action query (action query: A query that copies or changes data. Action queries include append, delete, make-table, and update queries. They are identified by an exclamation point (!) next to their names in the Navigation Pane.) by opening it in Datasheet view (Datasheet view: A view that displays data from a table, form, query, view, or stored procedure in a row-and-column format. In Datasheet view, you can edit fields, add and delete data, and search for data.). However, in Datasheet view you can preview the data that will be affected when you run the action query.

It's a good idea to make a copy of the data you are changing or moving in an action query, in case you need to restore the data to its original state after running the action query.

  1. Open the action query in Design view (Design view: A view that shows the design of these database objects: tables, queries, forms, reports, and macros. In Design view, you can create new database objects and modify the design of existing objects.).
  2. To preview the records that will be affected in Datasheet view, click View Button image on the toolbar and check the records. For each action query, you will see the following:
For this query The datasheet displays
Update The fields to be updated.
Delete The records to be deleted.
Make-table The fields to be included in the new table.
Append The records to be added to another table.
  1. To return to query Design view, click View Button image on the toolbar again. Make any changes you want in Design view.
  2. Click Run Button image on the toolbar to run the query.

 Note   To stop a query after you start it, press CTRL+BREAK.

When you run the make-table query, you get one table for each result. The first table created has the name defined in the query; subsequent tables have that name concatenated with a sequential number starting at 1.

 
 
Applies to:
Access 2003