Results 1 to 7 of 7
  1. #1
    vbafun is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    5

    Date Range search on Field with null Values

    Is it possible to do date range search on a field with Null values??

    I want to select all records even if the field is empty. If it value is Null then internally it should check the end date with the current date. If the current date is within the range it should display the record.


    Trying to figure this out for so long but was unable to do that.

    Any help will be much appreciated.


    Thanks in advance

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    There's at least three ways.

    You can add "OR Mydate IS NULL" to the WHERE clause,

    You can use NZ(MyDate,xxxxx) where xxxxx is Date() for the current date, or xxxx is DateAdd("d",1,Date()) for tomorrow, or whatever.

    You can create a global function MyFix(MyDate) that returns MyDate if not null, or overrides the Null with a chosen date if it is Null. This method is operationally identical to using NZ, but I think I once had a reason to do it.

  3. #3
    vbafun is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Now the subform is displaying records with null values as in the criteria section I used <datefield> between startdate and enddate or <datefield> is null.

    But the problem is as soon as the main form is loaded even before user enters start date and end date all the records have <datefield> Null is getting displayed.

    I want On load of main form only empty subform should be displayed. Once the user enters the start date and end date the subform should display all the records based on the criteria.

    Thanks.

  4. #4
    vbafun is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Dal Jeanis Thanks so much for your reply. As I mentioned adding Is Null in the where clause worked perfectly. But I want the records to be only displayed on a button click not on load.

    Thanks

  5. #5
    vbafun is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Got an alternate way, just made the subform invisible on Main form Load event and when start date and end date are entered and clicked on serach button made the subform visible = true.

    Any other solution is most welcomed.

    Thanks

  6. #6
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    That's workable. There are lots of options.

    You can set default values for the start and end dates that will result in no records being loaded.

    You can set defaults of Date() (which is today's date) for the start and end dates.

    You can set "DataEntry" to Yes and then switch it to No when the dates are selected.

  7. #7
    vbafun is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Quote Originally Posted by Dal Jeanis View Post
    That's workable. There are lots of options.

    You can set default values for the start and end dates that will result in no records being loaded.

    You can set defaults of Date() (which is today's date) for the start and end dates.

    You can set "DataEntry" to Yes and then switch it to No when the dates are selected.
    Thanks a lot Dal Jeanis. I tried DataEntry option and it worked like a charm. You solved my problem in no time.
    I really appreciate your help.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-11-2013, 09:49 AM
  2. Search Date Range with Null Sources
    By MintChipMadness in forum Forms
    Replies: 8
    Last Post: 08-23-2012, 08:56 AM
  3. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  4. Sum of Values over date range
    By bosnian in forum Queries
    Replies: 1
    Last Post: 01-12-2010, 03:41 PM
  5. Search form with a date range
    By mantro174 in forum Forms
    Replies: 1
    Last Post: 02-11-2009, 10:45 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