Results 1 to 9 of 9
  1. #1
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13

    SQL query in vba won't find records after a certain date??

    Hi
    I'm having a very strange problem with access. In vba I have an sql statement "select StudentID, CourseID from tblAttendance where AttendanceDate = #Whatever Date#".


    Now this works for all dates (as far as I can see) before 01/07/2013 but after that it just doesn't find any records. I have manually added dates and checked and it didn't work.
    Does anyone know how this could be possible? The date field is not in any relationship and it is Date/Time format. I don't even know how to go about troubleshooting this as it makes no sense to me.
    Thanks
    Edit: It thinks these records have a date below 1/7/2013 and it can find dates after 1/12/2013.
    Last edited by Fionn; 07-11-2013 at 06:44 AM.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Do you date fields have a time component to them?

    It is a bit tricky finding records that fall on a certain day if there is a time component, i.e.
    if the value of the date field is 1/7/2013 1:23 PM, using criteria of
    Code:
    =#1/7/2013#
    will NOT return that record, but
    Code:
    Between #1/7/2013# and #1/8/2013#
    will.

  3. #3
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    The time component is not the problem. When I add a date to the table I use the date picker and if I pick any date after 1/7/2013 it doesn't work. Say for example 1/1/2015 doesn't work but 1/1/2013 does. Unless for some reason a time (what time?) automatically gets added if I choose a date after 1/7/2013 but that doesn't make sense. It's really annoying me at this stage.
    Thanks anyways.
    Edit. Ok so tried just to solve it with your solution but as it happens while I can find dates above or below
    x/x/2013 it will not find any records in the year 2013 after July and before December. In fact it finds these records if I try less than 1/7/2013 despite them being greater than that date. And they don't come up when I say greater than 1/7/2013.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are you, perchance, using a European version of Access? I have seen lots of issues regarding dates, as there is often a mix-up between European and American date formats (m/d/y versus d/m/y), and what your system is defaulted to.

    Also, please post your SQL query.

  5. #5
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Ok my guess is its that european thing I'll check it now. I live in Ireland so yes the dates are in european style dd/mm/yyyy but maybe somewhere the dates are being processed in the American way.
    SQL "select StudentID, CourseID from tblAttendance where AttendanceDate = #1/7/2013#"

  6. #6
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Yes it is the American dates thing. It works to find 7/10/2013 with AttendanceDate = #10/7/2013#". Any ideas how to fix this?

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If the issue is with the Criteria (and not your date entry), here is a variation you can try that should work regardless of European/American format:
    Code:
    select StudentID, CourseID from tblAttendance where AttendanceDate = DateSerial(2013,7,1)

  8. #8
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Thanks but ultimately I want to put a date variable in there. Looks to be a common problem though looking at point 2 http://allenbrowne.com/ser-36.html.
    Got it working by changing the format of the date before executing the sql.
    Datez = Format$(Datez, "\#mm\/dd\/yyyy#")
    Messy but will do.
    Strange thing is that it only happens for certain dates.

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It stinks that you guys using the European versions have to do that. I am glad that I don't have to jump through those hoops.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-10-2012, 03:40 PM
  2. Query to find all records after a certain date
    By Matt Parsons in forum Queries
    Replies: 2
    Last Post: 08-24-2011, 06:22 AM
  3. How to find missing date query
    By twhite in forum Queries
    Replies: 8
    Last Post: 09-02-2010, 02:42 PM
  4. Query to find latest date
    By Lockrin in forum Access
    Replies: 2
    Last Post: 12-16-2009, 10:00 AM
  5. Find Records Query
    By sullyman in forum Programming
    Replies: 1
    Last Post: 10-28-2009, 08:49 AM

Tags for this Thread

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