ACC: How to Use Optional ParametersLast reviewed: August 28, 1997Article ID: Q141605 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. In Microsoft Access 7.0 and 97, you can create procedures that accept optional (not required) parameters when using the Optional keyword. This article shows two examples of how you can create and use procedures with optional parameters. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.
MORE INFORMATIONNOTE: In Microsoft Access 7.0, it was required that the variables declared as optional were placed at the end of the calling procedure and that the data type was explicitly a Variant. For example:
Sub MyTest(strTest1 As String, _ Optional Test2 As Variant, _ Optional Test3 As Variant)This was a requirement because optional parameters were passed at the end of the function call. In Microsoft Access 97 improvements have been made to the use of the Optional keyword by allowing the data type casting of the optional variable to be pre-assigned. For example:
Sub MyTest(strTest1 As String, _ Optional Test2 As String = "Test2", _ Optional Test3 As String = "Test3")This allows for the placement of the optional variable anywhere in the calling order of the function and allows you to test the contents of the variable.
Example 1
Example 2
REFERENCESFor more information about the Optional keyword, search the Help Index for "optional argument," or ask the Microsoft Access 97 Office Assistant. Keywords : kbprg PgmHowTo SynFnc Version : 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |