|
-
Jul 18th, 2006, 05:59 PM
#1
[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:

What am I doing wrong here? How can it not be either true or false? 
My first thought was that Null is only used to compare objects (like in VB.Net), but the immediate value told me otherwise.
Thanks!
Last edited by sevenhalo; Jul 18th, 2006 at 06:06 PM.
Reason: Changed to "not be either" for clarity.
-
Jul 18th, 2006, 07:01 PM
#2
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?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2006, 07:04 PM
#3
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).
-
Jul 18th, 2006, 07:19 PM
#4
Re: [Access 2002] Null evaluating to true in opposite comparisons
Close but no cigar! 
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2006, 07:30 PM
#5
Re: [Access 2002] Null evaluating to true in opposite comparisons
Doh!
I'll give it a shot tomorrow. Thanks.
-
Jul 19th, 2006, 07:25 AM
#6
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
-
Jul 19th, 2006, 08:37 AM
#7
Re: [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons
try
VB Code:
if not isnull(me.openargs) then strargs = me.Openargs
pete
-
Jul 19th, 2006, 11:20 AM
#8
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)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|