Problems with optional arguments

toast

Registered User.
Local time
Today, 20:44
Joined
Sep 2, 2011
Messages
87
I have a function which has several optional arguments.

These arguments are either forms or controls.

I need to test for how many of the optional arguments were passed.

I can't use IsMissing because they aren't Variants.

If I make the optional arguments variants I get a "ByRef argument type mismatch" error.

If I keep them as forms / controls, I cannot come up with a test for when they are missing:
IsNull always returns false
IsMissing always returns false
="" or =0 gives an "object variable or with block variable not set".

So how do I test for whether an optional form/control argument has been passed?

Any help greatly appreciated!
 
What method were you trying to use to pass the Control or Form? Strings? Try passing the object instead.
 
Without seeing your functions we can't guess what's going on. IsMissing() will only work if the optional argument is a variant.

If you don't want to set the data type of the optional parameter as Variant, then you can test the object as follows:
Code:
If obj Is Nothing Then
    Msgbox "It hasn't been set which may imply it wasn't passed"
End If
 
I am passing them as objects, and 'is nothing' worked perfectly.

Thank you both very much!
 
Dito! Thanks for posting back with your success.
 

Users who are viewing this thread

Back
Top Bottom