How do I test if optional arguments are supplied or not? -- in VB6 / VBA
Function func (Optional ByRef arg As Variant = Nothing)
If arg Is Nothing Then <----- run-time error 424 "object required"
MsgBox "NOT SENT"
End If
End Function
You can use the IsMissing() Function. But this one only works with the Variant datatype.
You can use something like:
"IsMissing"...Figured there would have to be a way. Thanks all!
SQL has a function, In(), where you can pass multiple arguments to see if the target value is in the list. I've always liked that as a solution, so here's my take on that, hope it helps:
So, that's obviously why I needed "IsMissing"; doesn't work without it.
If you are using a string or number variable you can check the value of the variable. For example:
This allows you to use non-variant variables.
With a variant I would use the NZ function:
It can be used with other data types too, just keep in mind that Zero counts as neither Null nor Zero-Length, so
nz(0,"")
still returns 0.If IsMissing(arg) Then ...