ACC97: Close Method Does Not Accept Missing Optional Argument

Last reviewed: October 16, 1997
Article ID: Q175215
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you use the Close method of the DoCmd object in Visual Basic for Applications, you cannot add optional arguments. If you try to use optional arguments with the Close method, you receive the following error message:

   Type Mismatch

CAUSE

The Close method requires an argument type to be set for the optional values somewhere in the code. The Type Mismatch error occurs because one or more of the arguments cannot be converted to an argument type without explicitly saying so in code.

RESOLUTION

You can use Visual Basic to check for missing arguments after the function has been called and set the argument type once you are running the code.

To set the type of optional arguments, follow these steps:

  1. Type the following procedure into a new module:

          Sub MyProgram(Optional a, Optional b, Optional c)
    
          Dim MyObjtype As Long
          Dim MyStr As String
          Dim MyPromptStr As Long
    
             ' Set the object variable to be the active database object.
    
            If (IsMissing(a)) Then MyObjtype = acDefault
    
             ' Set the string variable to an empty string.
    
            If (IsMissing(b)) Then MyStr = ""
    
             ' Set the prompt type to the Save message.
    
            If (IsMissing(c)) Then MyPromptStr = acSavePrompt
    
            DoCmd.Close MyObjtype, MyStr, MyPromptStr
    
          End Sub
    
    

  2. Press F5 to run the code.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Create a new module and type the following procedure:

          Sub Myprogram(Optional a, Optional b, Optional c)
    
            DoCmd.Close a, b, c
    
          End Sub
    
    

  3. Save the module, but leave it open.

  4. Press CTRL+G to open the Debug window.

  5. Type the following line in the Debug window, and then press ENTER:

          MyProgram
    

    Note that you receive the Type Mismatch error.


Additional query words: prb
Keywords : PgmObj kberrmsg
Version : WINDOWS:97
Platform : WINDOWS
Hardware : x86
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: October 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.