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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IsMissing Variable

Status
Not open for further replies.

JPeters

MIS
Jul 25, 2001
423
0
0
US
Having a small problem that I cannot seem to figure out.
I'm calling a function whose variables are all optional, and when I don't feed it the first variable, it thinks that I've actually fed it the variable. So my IsMissing() statements are returning false when they should be true! Let me explain through a little bit of the code - this is not the entire routine.

Code:
'Procedure calls the subroutine
Sub TEST()
LogError , , "Work", "Please", , ""
End Sub

'Open, and where the error occurs
Sub LogError(Optional errX As ErrObject, Optional LineNum As Long, Optional strProcName As String, Optional FieldValue As String, Optional FieldValue2 As String, Optional FieldValue3 As String, Optional FieldValue4 As String)

If IsMissing(errX) = False Then
' Store error information.
' Clear error.
strErrText = errX.Description
lngErrNum = errX.Number
errX.Clear
End If

Everytime it runs the code inside the If Then STatement even though it shouldn't since I'm not feeding it a value for errX. The IsMissing should return as True, and it should skip the code. I've tried it all different ways, if it's true, else statments, etc..

When I stop the code during it's runtime, and hold the mouse over Optional errX As ErrObject it shows "errX=Nothing". So is it assinging the value Nothing to my Optional variable... I've tried replacing IsMissing with If errX = Nothing ... and that doesn't work either.

-Josh

------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Josh, this is from Access help "IsMissing" function. Perhaps this will get you around this roadblock. Sorry I don't have first hand experience to pass on on this one.
Code:
Sub MySub(Optional MyVar As String = "specialvalue")
    If MyVar = "specialvalue" Then
        ' MyVar was omitted.
    Else
    ...
End Sub


---------------------------------------
The customer may not always be right, but the customer is ALWAYS the customer.
 
I'm not sure how the IsMissing(), recognizes "Object" data types. Variants are more common to use (I'm not sure if compulsory).

"IsMissing does not work on simple data types (such as Integer or Double) because, unlike Variants, they don't have a provision for a "missing" flag bit.
 
per dboulos' parenthitical statement (at least sort-of).

When you pass an empty string, it is not "MISSING", it is really just a zero length. Likewise, other "defined" types cannot be empty. Only VARIANTS can be tested for 'missing'.



MichaelRed
mlred@verizon.net

 
MichaelRed, Thank-you very much. that definately clarifies it for me. (I was suspicious, but not sure).
 
Yep, you guys are exactly right. After a little bit more research I found out about the variant. And while debugging the code, I saw that it was doing zero length - not missing.

Anyways, it works like a charm now. Thanks for everything.

-Josh

------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top