OFF: Error Message: Argument Not Optional (165538)
The information in this article applies to:
- Microsoft Access for Windows 95 7.0
- Microsoft Excel for Windows 5.0
- Microsoft Excel for Windows 5.0a
- Microsoft Excel for Windows 5.0c
- Microsoft Excel for Windows 95
- Microsoft Excel for Windows 95 7.0a
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q165538 SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.
When you use Automation code in one of the products listed at the beginning
of this article to manipulate an Automation server application that uses
newer version type libraries, such as those found in Microsoft Office 97
products, you may receive the following error message:
Argument not optional.
This article assumes that you are familiar with Visual Basic for
Applications.
CAUSE
Versions of Visual Basic for Applications in Microsoft Visual Basic 4.0 and
Microsoft Office 95 Professional only allowed optional arguments that were
of type Variant. Versions of Visual Basic for Applications in Microsoft
Visual Basic 5.0 and Microsoft Office 97 Professional now allow optional
arguments of non-Variant types.
As an example, the Microsoft DAO 3.5 Object Library contains methods which
include non-Variant optional arguments. Because this is not recognized in
products using older versions of Visual Basic for Applications, these
arguments must be explicitly specified. If omitted, you will receive the
error, "Argument not optional."
RESOLUTION
There are two possible resolutions to this behavior:
Method 1
When you use earlier version Automation client applications, do not rely on
the newer type libraries for the Automation servers. Instead, reference the
older version type libraries.
For example, do not reference the Microsoft DAO 3.5 Object Library in
Microsoft Visual Basic 4.0. Instead, reference the Microsoft DAO 3.0 Object
Library. Similarly, if you are using Microsoft Access 7.0, create a
reference to the Microsoft Excel 7.0 Object library and not the Microsoft
Excel 8.0 Object library.
Method 2
Explicitly specify all arguments when you execute a method in the new type
libraries. For example, when calling the Update method in the Microsoft DAO
3.5 Object Library, be sure to include values for its two arguments. The
line of code will look similar to the following:
MyRec.Update dbUpdateRegular, False
NOTE: The values dbUpdateRegular and False are the default values for the
Update method. By explicitly including them in the line of code, you will
not receive the "Argument not optional" error message.
For more information about the Update method, search the Help Index for
"Update method."
REFERENCES
For more information about creating references to other applications,
search the Help Index for "setting references, to applications."
| Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
|---|
| Keywords: | kberrmsg kbprb KB165538 |
|---|
|