Results 1 to 5 of 5
  1. #1
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156

    SQL Statement to find records with a Null date?

    Hi, all!



    I'm fighting with SQL statements again...and they're winning.

    My boss wanted some different data displayed, and now I need to be able to find records where a certain date field is null, meaning that a claim is still open. I've searched online, and seen all kinds of different ways people are saying to do it. The bulk of the SQL statement that I had before, that searches for dates within a range, will work for this, it's just finding those without dates that's tricky. Per the things I've read online, I've tried NULL, IS NULL, and Nz, and on both sides of the date field, but nothing works; when I run it, the debug.print looks right, but the text box gets a "0", every time, even though I've got test data that SHOULD be putting 2,000 in it.

    Can anyone tell where the NULL line is going wrong?
    Code:
         "SELECT Sum(tblMnlClaim.MClmRes) AS SumOfMClmRes " _
         & " FROM tblMnlClaim WHERE tblMnlClaim.EntID = '" & Me.ctlActEntID & "' " _
         & " AND tblMnlClaim.PolNum = '" & Me.ctltblRnwlTrack_PolNum & "'" _
         & " AND tblMnlClaim.MClmCxDt IS NULL;"

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I don't see anything wrong with the SQL syntax.

    This SQL is constructed in VBA then what do you do with it?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Thanks, June7!

    I'm feeding this into unbound fields on my form. I'm doing two different sets of SQL statements for each: one for dates that fall within the range, and the other for those without close dates (open claims). I'm using this under each to put them into the form:
    Code:
         Set db = CurrentDb
         Set rs = db.OpenRecordset(L36RSQL)
         Me.ctl36OR = rs!SumOfMClmRes
    And from there, I'll use VBA to add the proper sets, and place them in the bound fields. (I know I've read that you can do math with queries, but as shaky as my grasp of SQL is, I feel more comfortable doing it in VBA.)

  4. #4
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Is it possible that that date field isn't truly Null? I have it formatted as Date.

  5. #5
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Well, now I feel silly. While glaring at these SQL statements, I realized that there was one letter out of whack, and that's what threw them off. They work now.

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

Similar Threads

  1. Replies: 7
    Last Post: 07-17-2014, 12:42 PM
  2. Replies: 8
    Last Post: 07-11-2013, 07:24 AM
  3. Replies: 7
    Last Post: 09-10-2012, 03:40 PM
  4. Query to find all records after a certain date
    By Matt Parsons in forum Queries
    Replies: 2
    Last Post: 08-24-2011, 06:22 AM
  5. Replies: 2
    Last Post: 02-17-2010, 09:53 PM

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