IsMissing Function

Named Arguments

No

Syntax

IsMissing(argname)

argname

Use: Required

Data Type: Variant

The name of an optional procedure argument of type Variant.

Return Value

Boolean (True or False).

Description

Determines whether an argument has been passed to a procedure.

Rules at a Glance

  • If the argument name passed to IsMissing has not been passed to the procedure, True is returned; otherwise, IsMissing returns False.

  • False is returned if IsMissing is used on data types other than variants, which may lead to incorrect handling of optional arguments.

Programming Tips and Gotchas

  • Always use IsMissing to detect a missing optional variant parameter.

  • Version 5 of both VB and VBA for the first time allowed other data types to be used as optional arguments within procedure prototypes; previously, optional arguments had to be variants. However, if you use data types other than variants for optional arguments, you can't use the IsMissing function; instead, you must check for the uninitialized value of the data type. For example, if an integer argument is missing, its value is 0. This can cause confusion, because you have no way of knowing whether a was a legal value passed to the procedure or whether the argument was not passed at all. The only safe way to use optional arguments is to continue to use variants and to check their validity using the IsMissing function.

  • You can't use IsMissing on an optional ParamArray because the function always returns False. Instead, you should ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.