XL: Named Arguments Are Not Supported with DAO

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

SYMPTOMS

When you run a Microsoft Excel Visual Basic for Applications macro that uses Data Access Objects (DAO), you may receive one of the following error messages:

   Compile Error:
   Named Argument Not Found

   -or-

   Run-time error '438':
   Object doesn't support this property or method

CAUSE

DAO versions 3.0 and 3.5, which are included with Microsoft Excel 7.0 and 97 respectively, do not fully support named arguments. In some cases, named arguments will work without error, however, you should avoid using them.

RESOLUTION

To work around this behavior, use positional arguments instead of named arguments.

Microsoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

In a Visual Basic macro, when you call a Subroutine or Function, you can supply arguments positionally, in the order in which they appear in the definition of the procedure. Alternatively, you can supply the arguments by name without regard to position. However, with DAO properties and methods, Microsoft recommends that you use only positional arguments.

Example of the Problem

The DAO 3.5 OpenDatabase method uses the following syntax:

   Set <database> = OpenDatabase(dbname, options, readonly, connect)

If you use the OpenDatabase method by supplying named arguments in the macro, you may receive one of the errors described in this article. For example, when you run the following macro, the compile error "Named Argument Not Found" appears:

   Set DB = _
      OpenDatabase(dbname:= "C:\My Documents\DB1.MDB", readonly: = True)

Example of the Resolution

To correct the problem, use positional arguments. To do this, supply the arguments for the method in the correct position, where each argument is delimited by a comma, as shown in the following example:

   Set DB = OpenDatabase("C:\My Documents\DB1.MDB", , True)

STATUS

This behavior is by design in Microsoft Excel 97.

REFERENCES

For more information about named arguments, click the Index tab in Visual Basic for Applications Help, type the following text

   named arguments

click the Display button, and then double-click the "Understanding Named Arguments and Optional Arguments" topic.


Additional query words: XL97 8.0 8.00 parameter OpenRecordset
Keywords : kbcode kberrmsg kbprg xldao xl97vbmigrate
Version : WINDOWS:7.0,7.0a,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.