XL: "User-Defined Type Not Defined" Error Message Using DAO

Last reviewed: February 27, 1998
Article ID: Q145759
The information in this article applies to:
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows

SYMPTOMS

When you run a Microsoft Excel Visual Basic for Applications subroutine using data access objects (DAO), you may receive one of the following compile errors:

   User-Defined Type Not Defined

   -or-

   Sub or Function Not Defined

CAUSE

You may receive the error message when a subroutine contains code that uses the Microsoft DAO Object Library, and the library is not referenced.

RESOLUTION

In order to avoid the error message, perform the following steps.

Microsoft Excel 7.0

  1. Select a Module Sheet.

  2. On the Tools menu, click References.

    NOTE: It is necessary to be on a Module Sheet before you select the Tools menu because References is not available on the Tools menu on a worksheet, a dialog sheet, or a chart sheet.

  3. In the References dialog box, under Available References, click to select "Microsoft DAO 3.0 Object Library," and then click OK.

    If "Microsoft DAO 3.0 Object Library" is not listed in the list box under Available References, click Browse and look for the Dao3032.dll file. It should be located in:

           \Program Files\Common Files\Microsoft Shared\Dao\Dao3032.dll
    

    Select the file and click OK. This returns you to the References dialog box. Click OK.

Microsoft Excel 97

  1. In the Visual Basic Editor, click References on the Tools menu.

  2. In the References dialog box, under Available References, select "Microsoft DAO 3.5 Object Library," and then click OK.

    If "Microsoft DAO 3.5 Object Library" is not listed in the list box under Available References, click Browse and look for the Dao350.dll file. It should be located in:

           \Program Files\Common Files\Microsoft Shared\Dao\Dao350.dll
    

    Select the file and click OK. This returns you to the References dialog box. Click OK.

MORE INFORMATION

When you run a subroutine using DAO, and the DAO Object Library is not referenced, you receive one of the messages list above, depending on what code is written. If your code declares variables, for example

   Dim Db as Database
   Dim Rs as Recordset

you receive the "User-Defined Type Not Defined" message, and the subroutine fails in the variable declaration section.

If you did not declare your variables, you receive the "Sub or Function Not Defined" error message, and the subroutine fails at the first use of a statement that requires the DAO Object Library. This line is usually:

   Set Db = Workspaces(0).OpenDatabase(Path, <optional arguments>)

In this case, the subroutine fails when it encounters "Workspaces."


Additional query words: 7.00 8.00 97 XL97
Keywords : kberrmsg kbprg
Version : WINDOWS:7.0,97
Platform : WINDOWS


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