Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938

    Quote Originally Posted by pbaldy View Post
    No, I replace the null date with a date in the future. Comparing the criteria date to itself will result in all records being returned.

    Moke's suggestion is a good one.
    Yes I realise that, but that date should still be effective?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  2. #17
    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 Welshgasman View Post
    Yes I realise that, but that date should still be effective?
    The quirky part here is that the criteria entered by the user is where there would typically be a field name:

    WHERE ((([Forms]![frmVesselReport]![txtReportDate]) Between [SignOn] And [SignOff]))

    Thus if you use the criteria date you get (for example):

    WHERE 12/22/23 Between [SignOn] And 12/22/23

    In a sense comparing the criteria to itself. Every record meets the criteria. I used a future date:

    WHERE 12/22/23 Between [SignOn] And 12/31/29

    so only records with a SignOn date before the criteria qualify.

    But then again my brain is fried.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Thus if you use the criteria date you get (for example):

    WHERE 12/22/23 Between [SignOn] And 12/22/23
    but that only happens if signoff is null. If the signoff date is populated, then that value is being used.

    OP wanted all records where the specified date is between signon and signoff or is >=signon and signoff is null

    OP mentioned tried using OR - that would be the other way to go

    WHERE signOn<=[specified date] AND (signoff>=[specified date] OR [specified date] is null)

  4. #19
    Salty Mariner is offline Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    69
    You could also use something likeCode:
    Between [SignOn] And Nz([SignOff], DateAdd("y",50,date))

    which will never expire.
    Moke,

    I like it. You guys are great!

    Thanks.

  5. #20
    Salty Mariner is offline Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    69
    Quote Originally Posted by CJ_London View Post
    but that only happens if signoff is null. If the signoff date is populated, then that value is being used.

    OP wanted all records where the specified date is between signon and signoff or is >=signon and signoff is null

    OP mentioned tried using OR - that would be the other way to go

    WHERE signOn<=[specified date] AND (signoff>=[specified date] OR [specified date] is null)
    This was my initial inclination (using OR) However, I was unable to get the desired results, and it wasn't for lack of trying. Although it may have been my lack of experience as I am not a full-time developer... more of a "hobbyist" who who likes to create solutions for my work to help make peoples life easier.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-07-2019, 10:46 AM
  2. Calculating Work Days, help with Null Values for dates
    By rdougherty in forum Programming
    Replies: 9
    Last Post: 08-21-2018, 02:43 PM
  3. Replies: 2
    Last Post: 04-17-2017, 01:40 PM
  4. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  5. Replies: 2
    Last Post: 08-01-2011, 09:30 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