Results 1 to 14 of 14
  1. #1
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6

    Date range Q

    I am trying to use the date range expression off the MS web site and it not working (Between Date() And Date()-180) I am trying to search for records less then 180 days old. any thoughts

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    What is the field's datatype that you are working with and what is the definition of "not working." We can't view what you are seeing so not working to us could mean that it is sitting by the side of the road asking for handouts or it is playing chess in the street. More information would be helpful.

    Also, I don't think it makes a difference but you might want to have the earliest date first and then the later

    Between Date() -180 And Date()

  3. #3
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6
    the data type is dates (1/25/2011) it does not bring up any records and yes I tried switching the dates.

    Thanks

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Can you paste the entire SQL string for the query please?

  5. #5
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    markjet -

    Don’t know why the other function is not working.

    However, a while back, I used this and it worked for me…

    add this: >= DateAdd("d",-180, Now())

    to the criteria row of the date field you are trying to filter. See if it returns the records you need.

    All the best,


    Jim

  6. #6
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6
    Here is the SQL:

    SELECT tblTestReport.chrProductNumber, tblTestReport.chrProductName, tblTestReport.Report, tblTestReport.[AAMA Cert?], tblTestReport.dtmReportDate
    FROM tblTestReport
    WHERE (((tblTestReport.dtmReportDate) Between Date() And Date()-180));

  7. #7
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6
    thanks Jim but that one does not work either.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    The syntax you have

    Between Date() And Date()-180

    is correct and valid.

    Make sure your DATA TYPE for your date field is DATE/TIME and not text. If it's TEXT you will get nothing back (which seems to be your problem).

  9. #9
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6
    thanks for your response rprare but yes it set to DATE/TIME that the first thing I checked.

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Well you can do a couple of things, post a sample db or create a simple table with a date field then create a query on that date field and see if you can get it working for the sample table.

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    I've had issues with date/time fields which are storing times with the dates and regional settings interferring. So you could try this:

    Code:
    SELECT tblTestReport.chrProductNumber, tblTestReport.chrProductName, tblTestReport.Report, tblTestReport.[AAMA Cert?], tblTestReport.dtmReportDate
    FROM tblTestReport
    WHERE (((DateValue(Nz(tblTestReport.dtmReportDate,0))) Between Format(Date(), "\#mm\/dd\/yyyy\#") And Format(Date()-180, "\#mm\/dd\/yyyy\#")));

  12. #12
    markjet is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    6
    thanks for the work Bob, but I get the error data type mismatch in criteria expression.

  13. #13
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Do you have nulls in the date field at all?

    Also, I think you may be to a point where you will need to upload a copy of your database so we can play with it. It does take some messing with sometimes to get it just right.

  14. #14
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Post your sample db then, every test I've run works with the data I use.

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

Similar Threads

  1. Run query by date range
    By ARickert in forum Access
    Replies: 2
    Last Post: 06-23-2011, 10:54 AM
  2. Date range
    By eacollie in forum Queries
    Replies: 7
    Last Post: 06-05-2011, 03:38 PM
  3. Date Range Parameter help!?!?
    By dkstech in forum Access
    Replies: 1
    Last Post: 01-15-2011, 11:05 AM
  4. Date Range Failure
    By goodguy in forum Queries
    Replies: 4
    Last Post: 12-30-2010, 10:22 AM
  5. Date range help!!
    By bananatodd in forum Access
    Replies: 26
    Last Post: 10-18-2010, 01:57 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