ACC: How to Base Subforms on SQL Pass-Through Queries

Last reviewed: April 2, 1997
Article ID: Q112746
The information in this article applies to:
  • Microsoft Access 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes how to use an SQL pass-through query for a form's record source. It assumes that you know how to build and use SQL pass- through queries.

The following considerations should be kept in mind when you are using SQL pass-through queries for forms' record sources:

  • SQL pass-through query record sources are read-only.
  • The Query Builder does not save the connect string unless you save the query.
  • You cannot use a linked subform or subreport with a SQL pass-through query as its record source.

MORE INFORMATION

SQL Pass-Through Queries Are Read-Only

Forms based on SQL pass-through queries are read-only because SQL pass- through queries are read-only. The recordset returned by an SQL pass- through query is a snapshot, or read-only recordset. This behavior is by design. In order for the form to be updateable, base your form on an attached table with a unique index.

The Query Builder Does Not Save the Connect String

The RecordSource property's Query Builder displays a window that looks similar to a query's Design window. You use this window to build the SQL string or query for the RecordSource property. The Query Builder will set the RecordSource property to an SQL string if the SQL string is not saved as a query. If you save the string as a query, the name of the query will be used as the RecordSource property.

When you are using an SQL pass-through query created using the Query Builder, the ODBC connect string defined in that query will not be returned as part of the RecordSource property SQL string. This can produce the error message "Couldn't find input table or query '[Table from ODBC Server]'" because without the ODBC connect string, the form will look for a local table, instead of a table on the server. If you save the SQL string as a query, the RecordSource property will contain the name of the query instead of the SQL string, and the form will be able to retrieve the remote data correctly.

SQL Pass-Through Queries cannot use LinkChildFields/LinkMasterFields

The best way to use server-based data in a subform is to attach the remote table and then base the subform on the attachment.

If you base a subform directly on an SQL pass-through query, you may receive the following error message when you open the form:

   In Microsoft Access 7.0 and 97:

      You can't use a pass-through query or a non-fixed column crosstab
      query as a record source for a subform or subreport.

   In Microsoft Access 1.x and 2.0:

      The crosstab query underlying a subform or subreport must have fixed
      column headings.

This error will occur in Microsoft Access 7.0 and 97 if you have LinkMasterFields and LinkChildFields defined for the subform or subreport. In order to use an SQL pass-through query as a subform's record source in Microsoft Access 1.x and 2.0, you have to dynamically set the subform's RecordSource property in the main form's Load event. The following is an example of an OnLoad property event procedure in the main form MainForm that dynamically sets the RecordSource property in the subform SPTSubForm:

   Sub MainForm_OnLoad
     Me!SPTSubForm.Form.RecordSource = "[<Name of SQL pass-through query>]"
   End Sub

The subform itself should be saved without a RecordSource property. Note that the subform will not work if the LinkMasterFields and LinkChildFields properties are set. If you need to filter the records in the subform based on a value in the main form, either base your query on attached tables, or modify the QueryDef so that the query includes the value in the main form.

REFERENCES

For more information about SQL pass-through queries, search the Help Index for "pass-through queries," or ask the Microsoft Access 97 Office Assistant.


Keywords : FmsProp kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.