Results 1 to 11 of 11
  1. #1
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20

    Date Criteria Problem


    I am working with some data that has dates stored as text so I use the CDate function to change them It works fine.
    I now need to do some tests on them, so I do [ClosDate] - [RecDate] and it gives me the right number. I do a vartype and its comes back as a double.
    I now need to filter for anything >28, so i enter that on the Criteria line and when i run the query I get asked for parameter values for ClosDate and Recdate.
    Anyone any idea what i am doing wrong please.

    PS I did try DateDiff and I think I got a data type miss match error when I entered the criteria.

    Any help much appreciated - this is taking too long!!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post the SQL code of your query?

  3. #3
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    Hertis!
    SELECT dbo_CallLog.CallID, dbo_CallLog.CallType, dbo_CallLog.CallStatus, dbo_CallLog.Priority, dbo_CallLog.ClosedDate, dbo_CallLog.RecvdDate, CDate([RecvdDate]) AS RecDate, CDate([ClosedDate]) AS ClosDate, ([ClosDate]-[RecDate]) AS Expr1, VarType([expr1]) AS Expr2
    FROM dbo_CallLog;

  4. #4
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    and with the criteria
    SELECT dbo_CallLog.CallID, dbo_CallLog.CallType, dbo_CallLog.CallStatus, dbo_CallLog.Priority, dbo_CallLog.ClosedDate, dbo_CallLog.RecvdDate, CDate([RecvdDate]) AS RecDate, CDate([ClosedDate]) AS ClosDate, ([ClosDate]-[RecDate]) AS Expr1, VarType([expr1]) AS Expr2
    FROM dbo_CallLog
    WHERE (((([ClosDate]-[RecDate]))>28));

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Give this a try:

    Code:
    SELECT
        dbo_CallLog.CallID, 
        dbo_CallLog.CallType, 
        dbo_CallLog.CallStatus, 
        dbo_CallLog.Priority, 
        dbo_CallLog.ClosedDate, 
        dbo_CallLog.RecvdDate,   
        CDate([RecvdDate])AS RecDate, 
        CDate([ClosedDate])AS ClosDate
    FROM dbo_CallLog
    WHERE (CDate([ClosDate])-CDate([RecDate]))>28;
    

  6. #6
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    Still get the parameter value prompt - followed by some other stuff about the expression being typed incorrectly or the query being too complex! (I did copy and paste it)

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Oops, I see the problem,and I missed it initially. You cannot use calculated fields in your criteria like that. Use the calculation itself, i.e.

    Code:
    SELECT
        dbo_CallLog.CallID, 
        dbo_CallLog.CallType, 
        dbo_CallLog.CallStatus, 
        dbo_CallLog.Priority, 
        dbo_CallLog.ClosedDate, 
        dbo_CallLog.RecvdDate, 
        CDate([RecvdDate])AS RecDate, 
        CDate([ClosedDate])AS ClosDate
    FROM dbo_CallLog
    WHERE (CDate([ClosedDate])- CDate([RecvdDate]))>28;
    

  8. #8
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    Thanks for your help but still getting the error "Date type missmatch in crieria expression"

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you run the query without the criteria, does it work?
    If so, take a look at your CDate conversions. Do you have any errors or blank/null values?
    If so, those will obviously mess up the criteria calculation, and need to be accounted for.

  10. #10
    stumped is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    Point 1, yes it runs correctly.
    Points 2 and 3 - haven't checked yet but I think you have it - I recall that I had to test extensively for blank/null values on this dataset when I wrote a function that involved dates earlier. Thanks, I should have though of that!!

  11. #11
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    To handle the Nulls, you can use the NZ function to replace Nulls with some default value,
    and/or
    you can use "Is Not Null" in the criteria fields to weed those out.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2012, 03:05 PM
  2. problem with date criteria
    By sbrooks1763 in forum Queries
    Replies: 1
    Last Post: 01-10-2012, 07:30 AM
  3. >Date() criteria
    By BED in forum Queries
    Replies: 3
    Last Post: 12-15-2010, 03:29 AM
  4. Criteria for date due
    By Desstro in forum Queries
    Replies: 4
    Last Post: 11-30-2010, 12:54 PM
  5. Date Criteria
    By tcollins02 in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 08:27 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