Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is IsMissing not working? 1

Status
Not open for further replies.

Petemush

Technical User
Jun 21, 2002
255
GB
Hi,

I have a procedure that contains Optional arguments. In the procedure I use IsMissing to determine whether an argument has been passed and carry out some extra code if it has been.

Unfortunately, IsMissing doesn't seem to be working properly, or I'm using it incorrectly.

To double check, I dimmed a boolean "test", set it to the value of IsMissing(param_name) and set a breakpoint. I then called the procedure omitting param_name as an argument. I then checked the value of test but it remained false.

Hopefully I'm calling it wrong but I can't work out how. Perhaps someone can help?

I call it using

Private Sub ArrangeBy_Check_AfterUpdate()

Call After_Update_Checkboxes([ArrangeBy Check], [Arranged By])

End Sub

Can anyone see anything wrong?

Cheers,

Pete
 
In your code [ArrangeBy Check] and [Arranged By] are arguments and are being passed. Therefore, IsMissing() will report that the 2 arguments were passed. Even if both are empty strings. Take out one of the arguments and IsMissing() should report it missing. IF you are looking to carry out code based on the arguments, why don't you always pass a value to indicate to do more code.

Tom
 
The procedure I'm calling actually has four arguments.


Public Sub After_Update_Checkboxes(checkbox_name As CheckBox, _
control_name As Control, _
Optional changeCost As String, _
Optional eqOp As OptionGroup)


I'm testing the fourth one with


test = IsMissing(eqOp)


When using the code in my first post, with just two arguments, the IsMissing still remains false.

Cheers,

pete
 
You must look at the line of code that calls the procedure:

Call After_Update_Checkboxes(Arg1,Arg2,Arg3,Arg4)

If you do have an Arg3 and Arg4, as in the above example, then the arguments are not missing, they were passed.

If you call like this:

Call After_Update_Checkboxes(Arg1,Arg2)

Then Arg3 and Arg4 are now missing and IsMissing() should report that these two are missing.

Tom
 
Trust me,

Everything that calls this procedure, that doesn't need to pass four arguments, is coded like this:

Call After_Update_Checkboxes(Arg1,Arg2)

Then in the procedure called I use the IsMissing method like so:

Public Sub After_Update_Checkboxes(checkbox_name As CheckBox, _
control_name As Control, _
Optional changeCost As String, _
Optional eqOp As OptionGroup)

Dim test As Boolean
test = IsMissing(eqOp)

If Not (test) Then...............

The If condition isn't relevant because I use a breakpoint at the "test =" line and step on and then check the value of test.

It is always false.

I'm starting to go insane!

Cheers,

Pete
 
At your breakpoint, use the debugger and find out what value is 'eqOp'. It must be something if its not missing.

Tom
 
Yeah, it says:

Nothing

I though that was how IsMissing determined it was missing.

Cheers,

Pete
 
I found this article on the subject at the Microsoft
Knowledge Base, which says that IsMissing always returns
False for variables that aren't Variant data types:


The variable eqOp is an Object, not a Variant, so IsMissing
would return False in this case. Could you use "Is Nothing"
to test whether it was passed? (I'm quite a novice at
VBA and Access.)
 
Well mikevh, you're a genius.

I did wonder about the fact that the arguments weren't variants but nothing clicked. Thank you so much!

I'll have to pass default values and test the value instead of using IsMissing.

Cheers everyone else for their suggestions, I will now leave quietly.

Cheers,

Pete
 
Just to note, another solution (an obvious one I know) which i've now used, is to have the optional arguments as Variants.

I didn't know you could have an Option Group as a Variant but it works.

Cheers,

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top