Results 1 to 8 of 8

Thread: [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Resolved [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons

    I have the following code:
    VB Code:
    1. Private Sub Form_Load()
    2.     If Me.OpenArgs = Null Then      
    3.         DoCmd.GoToRecord , , acNewRec
    4.     Else                              
    5.             'Do something else
    6.     End If
    7. End Sub
    Everytime I step through it, it drops to the else clause. If I flip the comparison to:
    VB Code:
    1. Private Sub Form_Load()
    2.     If Me.OpenArgs <> Null Then      
    3.         DoCmd.GoToRecord , , acNewRec
    4.     Else                              
    5.             'Do something else            
    6.     End If
    7. 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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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).

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Private Sub Form_Load()
    2.     Dim strArgs As String
    3.     strArgs = vbNullString 'Initialize var
    4.     strArgs = Me.OpenArgs
    5.     If Len(strArgs) > 0 Then
    6.         'Args passed
    7.     Else
    8.         'No args passed
    9.     End if
    10. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: [Access 2002] Null evaluating to true in opposite comparisons

    Doh!

    I'll give it a shot tomorrow. Thanks.

  6. #6

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: [Access 2002] Null evaluating to true in opposite comparisons

    Ok, I gave it a shot with the following:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim strArgs As String
    3.     strArgs = vbNullString 'Initialize var
    4.     [HL]strArgs = Me.OpenArgs[/HL]
    5.  
    6.     If Len(strArgs) = 0 Then      
    7.         DoCmd.GoToRecord , , acNewRec
    8.     Else                              
    9.            
    10.     End If
    11. 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

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] [Access 2002] Null evaluating to true in opposite comparisons

    try
    VB Code:
    1. if not isnull(me.openargs) then strargs = me.Openargs

    pete

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width