IsMissing Function

Description

Returns a Boolean value indicating whether an optional argument has been passed to a procedure.

Syntax

IsMissing(argname)

The argname argument is the name of an optional procedure argument.

Remarks

The IsMissing function is used in a procedure that has optional arguments, including ParamArray arguments, to determine whether an argument has been passed to the procedure. IsMissing returns True if no value has been passed for the specified argument; otherwise, it returns False. If IsMissing returns True for an argument, use of the missing argument in other code may cause a user-defined error. If IsMissing is used on a ParamArray argument, it always returns False.

See Also

Function Statement, IsArray Function, IsDate Function, IsEmpty Function, IsError Function, IsNull Function, IsNumeric Function, IsObject Function, Property Get Statement, Property Let Statement, Property Set Statement, Sub Statement, TypeName Function, Variant Data Type, VarType Function.

Example

This example uses the IsMissing function to check if an optional argument has been passed to a user-defined procedure.


' The following statements call the user-defined function procedure.= ReturnTwice()        ' Returns Null.= ReturnTwice(2)        ' Returns 4.

' Function procedure definition.ReturnTwice(Optional A)
    If IsMissing(A) Then
        ' If argument is missing, return a Null.
        ReturnTwice = Null
    Else
        ' If argument is present, return twice the value.
        ReturnTwice = A * 2
    End IfFunction

The following example uses the IsMissing function to determine whether an argument has been passed to the function. If not, a message prompts the user to supply a value.


Sub RunQuery(Optional varQueryName As Variant)
    Dim strGetQuery As String

    ' Determine if optional argument was passed.
    If IsMissing(varQueryName) Then
        ' If argument was not passed, prompt for query to run.
        varGetQuery = InputBox("Enter query name.")
        DoCmd.OpenQuery varGetQuery
    Else
        ' If argument was passed, run that query.
        DoCmd.OpenQuery varQueryName
    End IfSub