Results 1 to 13 of 13
  1. #1
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24

    Invalid use of Null

    Good Afternoon. I am getting an error "Invalid use of Null" on my query. I am trying to add a filter where the date is in the future in the Expr1: CDate([HrgDate]) column. This column hrgdate, is being formatted as a string in the database and so I'm trying to convert it to a date and then use >date() to find the values that are in the future. My SQL code is below. Can anybody please lend assistance? Thank you!



    Code:
    SELECT dbo_Entities.EntityID AS [File#], CDate([HrgDate]) AS Expr1
    
    
    FROM (dbo_Entities LEFT JOIN dbo_FCLIT ON dbo_Entities.EntityNum = dbo_FCLIT.Entitynum) LEFT JOIN dbo_Action_Hrg ON dbo_FCLIT.LookupAnchor = dbo_Action_Hrg.LookupAnchor
    
    WHERE (((dbo_Entities.ClosedFlag)=0) AND 
    ((dbo_Entities.DateClosed) Is Not Null) AND 
    (dbo_FCLIT.StartAction) Is Not Null) AND 
    ((dbo_FCLIT.End) Is Null) AND 
    ((dbo_Entities.EntityID) Not Like "*TEST*") AND 
    ((CDate([HrgDate]))>Date()));

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, the CDate() will error on a Null. Are there any in that field?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    Yes there are, and it is returning errors. I just figured that the >date() where clause would basically pull those out anyway. Can you please suggest a better way to do it? I'm quite new.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    SELECT executes before WHERE

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How can it evaluate the >Date() without trying to do the conversion first? You can try wrapping the field in the Nz() function, like CDate(Nz([HrgDate], #1/1/2001#))

    ItsMe, do you have a cite for that? It conflicts with what I've heard previously.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by pbaldy View Post
    ItsMe, do you have a cite for that? It conflicts with what I've heard previously.
    Not specific for Access but specific for SQL server. I put it my notes and, just now, recalled it from memory. Maybe a year ago, I was watching tutorials on Channel 9. What I wrote in my notes was based on the tutorial. Later, I will look for the vid on my hard drive or even just the notes. I will post up here afterwards.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Mine was also for SQL Server, and says something different than your source:

    http://blog.sqlauthority.com/2009/04...ent-execution/

    I've heard something similar for Access but don't have a cite for it. They also had other clauses before SELECT.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Paul,

    It was bugging me so I found a screenshot. You are correct and I did not recall correctly. So here is the order for T-SQL.

    .
    Click image for larger version. 

Name:	SQL_Eval.jpg 
Views:	4 
Size:	40.0 KB 
ID:	20359

  9. #9
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    This worked great. You're a wizard. Is Nz basically the equivalent of Iferror?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No worries, I just wanted to make sure I wasn't screwed up. In a way it makes sense, as evaluating the WHERE clause to restrict the data set before performing other operations would be more efficient.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by hellfire45 View Post
    This worked great. You're a wizard. Is Nz basically the equivalent of Iferror?
    I don't think so. Nz() replaces Null with another value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by pbaldy View Post
    I've heard something similar for Access but don't have a cite for it. They also had other clauses before SELECT.
    I would be interested in seeing something specific for Access. In the meantime, I will do a better job remembering the T-SQL evaluation order. Have a good day Paul.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by ItsMe View Post
    I would be interested in seeing something specific for Access. In the meantime, I will do a better job remembering the T-SQL evaluation order. Have a good day Paul.
    So would I. You too!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-13-2013, 08:56 AM
  2. Invalid use of null
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 03-24-2013, 11:05 PM
  3. Invalid use of Null
    By justauser in forum Forms
    Replies: 2
    Last Post: 11-28-2012, 12:33 PM
  4. Invalid use of Null
    By Wayne311 in forum Programming
    Replies: 4
    Last Post: 01-27-2011, 05:10 PM
  5. Invalid Use of Null!?!
    By Kipster1203 in forum Access
    Replies: 4
    Last Post: 05-13-2010, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums