Excel: Using Excel's Macro Recorder to Record an SQL Query

Last reviewed: November 4, 1994
Article ID: Q80111
Summary:

When using the Microsoft Excel Macro Recoder to record a SQL Query in a macro that opens a Query file created in Q+E, the header line "Q+E for <Driver>" must be removed. If the header line is not removed, it will be included in the recorded macro code and cause the macro to fail when executed again.

More Information:

A query file created and saved in Q+E will always include the line "Q+E for <Driver>" as a header line. When the query file is executed in Q+E or Excel, that line is ignored. However, if the file is used when recording a SQL Query macro, the line is included in the macro code. When recording the macro, the query will execute properly; however, the inclusion of the header line will cause the macro to fail when executed again.

If the line is not removed, the macro code will appear as follows:

   =DB.SQL.QUERY(2,"Q+E 3.0 for SQLServerUSE pubs;SELECT * FROM
   SQLserver|dbo.authors;",1,,FALSE)

This line will fail when the macro is executed again.

With the header line removed, a properly recorded macro line will appear as follows:

   =DB.SQL.QUERY(2,"USE pubs;SELECT * FROM
   SQLserver|dbo.authors;",1,,FALSE)

This line will not fail when the macro is executed again.

Reference(s):

"Q+E for Microsoft Excel User's Guide," version 3.0, pages 33-36, 70-71

"Microsoft Excel User's Guide," for Windows, version 3.0, pages 582-586


KBCategory: kbother
KBSubcategory:

Additional reference words: 3.00 3.0


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: November 4, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.