Results 1 to 3 of 3
  1. #1
    SusanCoder is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    30

    calculated date field not returning correct results from variable criteria

    I'm using the Access query design view.



    These are working as designed:

    Query1: I calculate the date at age 21 using the date of birth field [DOB] with formula
    Code:
    DOB21: DateAdd("yyyy",21,[DOB])
    . In the same query I calculate 30 days before DOB21 as
    Code:
    30DaysBeforeDOB21: DateAdd("d",-30,[DOB21])
    . So far so good and the correct dates are in the results. fyi...both calculated date fields are formatted as Short Date in the query's field properties. The DOB field is formatted as Short Date in the table where it's stored.

    Query2: I include the [30DaysBeforeDOB21] field from Query1 and add the criteria
    Code:
    Between #2/1/2023# And #2/8/2023#
    . The results are correct.

    This is not working:

    My issue occurs when I try to add variable criteria for the [30DaysBeforeDOB21] field. When I use the criteria
    Code:
     Between [Begin Date] and [End Date]
    and enter the dates in the prompts when the query is run, the results are incorrect. While the results come back in the date format, the results contain records that are not between the dates in the criteria.

    Thanks for your advice.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Can try to wrap them in CDate():
    Code:
    Between CDate([Begin Date]) and CDate([End Date])
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    SusanCoder is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    30
    Yes! I did and that worked! Thanks so much Vlad I appreciate you. I'll mark this thread as answered correctly.

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

Similar Threads

  1. DateDiff not returning correct results
    By Pilot in forum Modules
    Replies: 6
    Last Post: 01-13-2020, 04:46 PM
  2. Query not returning correct results
    By badmem in forum Queries
    Replies: 6
    Last Post: 07-26-2016, 10:16 AM
  3. Replies: 6
    Last Post: 06-17-2015, 11:53 AM
  4. Replies: 3
    Last Post: 02-26-2015, 11:01 AM
  5. Setting criteria in a calculated date field
    By SteveReberger in forum Access
    Replies: 0
    Last Post: 10-29-2008, 06:58 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