Results 1 to 4 of 4
  1. #1
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19

    more trouble with text fields as dates

    I have read about a hundred of these, but still cannot get my query to work.

    I have a table which I inherited (and cannot modify) which uses text fields as dates.
    They are typically set as "mm/yy".

    I was able to use CDate to convert these to dates that Access recognizes.



    Here is the SQL for that, where the text field for the date is [BLS expires]:

    Code:
    SELECT [2012StaffCerts].Name, [2012StaffCerts].Title, CDate([2012StaffCerts].[BLS expires]) AS [BLS-Exp]
    FROM 2012StaffCerts

    I really need to be able to compare them against some other date, e.g., to return
    all rows where the date is less than some future date.

    This is what I think should work, but does not:

    Code:
    SELECT [2012StaffCerts].Name, [2012StaffCerts].Title, CDate([2012StaffCerts].[BLS expires]) AS [BLS-Exp]
    FROM 2012StaffCerts
    WHERE CDate(Nz([2012StaffCerts].[BLS expires],Date()) ) < CDate("05/31/2012");
    The error I get is "Data type mismatch in criteria expression".

    My ultimate goal is to provide either a parametrized query where the date is passed in, or
    perhaps to simply use something like "Date()+30".

    Thanks in advance!

    Mitch

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I was playing around with a query similar to what you described and the query worked just fine. I wonder if you have some data in your text date field that cannot be converted to a valid date. That is something you may want to check perhaps by using the isdate() function.

  3. #3
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19

    invalid charcters for date conversion

    Quote Originally Posted by jzwp11 View Post
    I was playing around with a query similar to what you described and the query worked just fine. I wonder if you have some data in your text date field that cannot be converted to a valid date. That is something you may want to check perhaps by using the isdate() function.
    I did not think of that, but looking at the data, I do see two cases of extra characters...I am 99.9% sure
    that is the problem.

    Thanks!

    Mitch

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. BTW, I would use the dateadd() function rather than Date()+30

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

Similar Threads

  1. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  2. Bounds fields trouble
    By accessnewb in forum Programming
    Replies: 12
    Last Post: 08-08-2011, 02:18 PM
  3. Replies: 1
    Last Post: 05-30-2011, 06:03 PM
  4. Having trouble with moving text to table
    By geoffwbailey in forum Programming
    Replies: 3
    Last Post: 06-17-2010, 11:00 AM
  5. Having trouble with dates in my Data Base!!!!
    By BigPhil in forum Queries
    Replies: 4
    Last Post: 02-15-2006, 12:47 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