Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Error When Object Methods Rely on Optional Arguments


View products that this article applies to.

This article was previously published under Q197950
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Symptoms

If an object's method within a subroutine or a function uses the optional arguments allowed by the subroutine or the function, and one or more of the optional arguments are excluded at the time that the subroutine or the function is called, one of the following run-time errors can occur:
Run-time error '13':
Type mismatch
-or-
Run-time error '2493':
This action requires an Object Name argument.

↑ Back to the top


Cause

The object's method is expecting one or more of its arguments to have some value, and one of the arguments has either been assigned an unknown value, or the value has been excluded altogether.

↑ Back to the top


Resolution

Functions such as IsMissing() or IsNull() within Visual Basic for Applications can be used to check for any excluded optional arguments. Within the subroutine or the function that is called, programmatically test to see if one or more of the optional arguments was excluded. For example:
  1. Type the following two procedures into a new module:
    Sub Prog1(Optional a, Optional b, Optional c)
        If IsMissing(a) Then a = acDefault
        If IsMissing(b) Then b = ""
        If IsMissing(C) Then c = acSavePrompt
        DoCmd.Close a, b, c
    End Sub
    
    Sub Prog2(Optional a As Long, Optional b As String, Optional c As Long)
        If a = 0 Then a = acDefault
        If IsNull(b) Then b = ""
        If C = 0 Then c = acSavePrompt
        DoCmd.Close a, b, c
    End Sub
    					
  2. Press CTRL+G to open and move focus to the Immediate window.
  3. Type the following line in the Immediate window, and then press ENTER:
    Prog1
    					
  4. Type the following line in the Immediate window, and then press ENTER:
    Prog2
    					

↑ Back to the top


More information

If you have programmatically specified that one or more arguments of a method should be used, and you do not supply an argument at run time or you do not supply a valid value for an argument, you will receive the run-time error.

To illustrate this point, the "Steps to Reproduce Behavior" section will use the Close method of the DoCmd object within a subroutine, where the subroutine allows for optional arguments. However, when the subroutine is called, the optional arguments are excluded in order to generate the run-time error.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.
  2. Create a new module and type the following procedure:
    Sub Prog(Optional a, Optional b, Optional c)
       DoCmd.Close a, b, c
    End Sub
    					
  3. Save the module as modTest.
  4. Press CTRL+G to open and move focus to the Immediate window.
  5. Type the following line in the Immediate window, and then press ENTER:
    Prog
    						

    Note that you receive the "Type Mismatch" run-time error.
  6. Modify the arguments within the subroutine as follows:
    Sub Prog(Optional a As Long, Optional b As String, Optional c As Long)
    					
  7. Repeat steps 3 through 5.

    Note that you receive the "This action requires an Object Name argument" run-time error.

↑ Back to the top


Keywords: KB197950, kbprb

↑ Back to the top

Article Info
Article ID : 197950
Revision : 2
Created on : 7/16/2004
Published on : 7/16/2004
Exists online : False
Views : 484