XL: ShowDataForm Method Fails If Data Can't Be Found

Last reviewed: February 3, 1998
Article ID: Q110462

The information in this article applies to:
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows, version 5.0
  • Microsoft Excel for the Macintosh, version 5.0
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

In Microsoft Excel, when you use the Visual Basic ShowDataForm method, you may receive the following error message:

   Run-time error '1004':
   ShowDataForm method of Worksheet class failed

CAUSE

This error occurs because Microsoft Excel is unable to find a data list on the worksheet you specified in the Visual Basic statement.

When you use the ShowDataForm method, Microsoft Excel looks for the data list in two places:

  • The defined name "Database." If a range has been defined as the database, Microsoft Excel will display the data form, and the data in that range will be accessible.
  • Cells A1:B2 on the specified worksheet. Microsoft Excel will attempt to find a list whose upper-left corner lies in the range A1:B2. If a list is found, Microsoft Excel will display the data form and the data in the list will be accessible.

WORKAROUNDS

Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp
                                     
To work around this problem, define your data with the defined name "database" or move your data so that its upper-left corner is located in any of the four cells in the range A1:B2.

To define your data with the defined name "database"

  1. Select the range that contains your data.

  2. On the Insert menu, point to Name, and then click Define.

  3. In the Name box, type "<Sheetname>!Database" (without the quotation marks), where <Sheetname> is the name of the active worksheet.

  4. Click OK to accept the change.

When you execute the ShowDataForm method and specify the worksheet, the data form will be displayed with the correct data.

To automate the above process, select the data that you want to be included in your database (including column headings), and include the following in your Visual Basic procedure:

   ActiveWorkbook.Names.Add Name:=ActiveSheet.Name & _
      "!Database", RefersToR1C1:=Selection
   ActiveSheet.ShowDataForm

NOTE: For information on variations you can use for this code, see the "More Information" section of this article.

MORE INFORMATION

The Visual Basic ShowDataForm method is used to display a data form. You can use a data form to view a list of data or to enter new data into a list. You might use the ShowDataForm method in either of the following ways:

   ActiveSheet.ShowDataForm

   -or-

   Worksheets("Sheet1").ShowDataForm

REFERENCES

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for
               Applications


Additional query words: 5.00 7.00 8.00 DataForm Record
Keywords : kbcode kbprg PgmOthr
Version : WINDOWS: 5.0,5.0c,7.0,97; MACINTOSH: 5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


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