Error '1004' When Using the SQLRequest Macro Function

Last reviewed: September 13, 1996
Article ID: Q124226
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In the versions of Microsoft Excel listed above, you may receive the following error message when you use the SQLRequest function in a Visual Basic, Applications Edition, macro:

   Run-time error '1004':
   Run method of Application class failed

This error message will occur if the SQLRequest function returns a result set containing more than 4095 elements.

CAUSE

The SQLRequest function has an argument called ColNamesLogical, which specifies whether to return field headings. If this argument is set to TRUE, then in the case above you can only return up to 4094 elements or cells and 1 field heading. If ColNamesLogical is set to FALSE or is omitted, then you can return only 4095 records.

RESOLUTION

To return a result set with more than 4095 elements, use the SQLRetrieve function as it's used in the following sample procedure:

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

Sample Visual Basic Procedure

This procedure opens a channel to a given data source, executes a query, retrieves the result set to the active cell on the active worksheet, and closes the channel opened by SQLOpen:

   Sub GetMyData()
       chan = SQLOpen("DSN=Nwind")

       ' Get all columns and records from the orders table.
       SQLExecQuery chan, "SELECT * FROM orders"

       ' Retrieve the results from SQLExecQuery to the active cell
       ' and include the field headings.
       SQLRetrieve chan, ActiveCell, , , True

       SQLClose chan
   End Sub

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

For more information on the SQLRequest and SQLRetrieve functions choose the Search button in Visual Basic Reference Help and type:

   SQLRequest

   -or-

   SQLRetrieve.


KBCategory: kbprg kbcode
KBSubcategory:

Additional reference words: 7.00 5.00 5.00c



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: September 13, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.