[RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons
I have the following code:
VB Code:
Private Sub Form_Load()
If Me.OpenArgs = Null Then
DoCmd.GoToRecord , , acNewRec
Else
'Do something else
End If
End Sub
Everytime I step through it, it drops to the else clause. If I flip the comparison to:
VB Code:
Private Sub Form_Load()
If Me.OpenArgs <> Null Then
DoCmd.GoToRecord , , acNewRec
Else
'Do something else
End If
End Sub
It still drops to the else clause. I checked the value of Me.OpenArgs to see what it actually is:
http://i34.photobucket.com/albums/d1...o/evaluate.jpg
What am I doing wrong here? How can it not be either true or false? :cry:
My first thought was that Null is only used to compare objects (like in VB.Net), but the immediate value told me otherwise.
Thanks!
Re: [Access 2002] Null evaluating to true in opposite comparisons
Null is an unknown value so it can not be evaluated at all. There are the IsNull and other null comparison functions. It just depends on your situation.
IsNull, IsEmpty, NullIf, nz, NullString are all possibilities.
What is OpenArgs data type?
Re: [Access 2002] Null evaluating to true in opposite comparisons
String I would assume? It's just the opening arguements you pass to the access form. It's built in (I didn't create it).
Re: [Access 2002] Null evaluating to true in opposite comparisons
Close but no cigar! :D
Quote:
Determines the string expression specified by the OpenArgs argument of the OpenForm method that opened a form. Read/write Variant.
VB Code:
Private Sub Form_Load()
Dim strArgs As String
strArgs = vbNullString 'Initialize var
strArgs = Me.OpenArgs
If Len(strArgs) > 0 Then
'Args passed
Else
'No args passed
End if
End Sub
Re: [Access 2002] Null evaluating to true in opposite comparisons
Doh!
I'll give it a shot tomorrow. Thanks. :D
Re: [Access 2002] Null evaluating to true in opposite comparisons
Ok, I gave it a shot with the following:
VB Code:
Private Sub Form_Load()
Dim strArgs As String
strArgs = vbNullString 'Initialize var
[HL]strArgs = Me.OpenArgs[/HL]
If Len(strArgs) = 0 Then
DoCmd.GoToRecord , , acNewRec
Else
End If
End Sub
It breaks on the highlighted line with an "Invalid use of null" error.
BUT!!!
Using the other suggesition you offered (IsNull), I was able to evaluate that.
Thanks Rob :thumb:
Re: [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons
try
VB Code:
if not isnull(me.openargs) then strargs = me.Openargs
pete
Re: [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons
Or using and IIF with an IsNull in it would work too.
VB Code:
strArgs = IIf(IsNull(Me.OpenArgs) = True, vbNullString, Me.OpenArgs)