Results 1 to 7 of 7
  1. #1
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116

    Cant figure error with calendar issue

    Hi Everyone,

    I am attempting to build an Overtime database in access 2010 and I am about half way through it as I still ahve to sort out the security side of it yet (keeping a log of all changes), The thing is I've been really struggling with my limited knowledge of Access (for days now really) to figure out an issue I have with my SQL UPDATES and INSERT, Essentially my issue is the logged on user enters an/or there own HR-Id, then they are presented with a form that presents an interactive calendar, simply put ..if the users double clicks any date they can then book(eg ..show they are willing to work a shift on that date and the colour of the calendar will reflect this), the calendar is set up where each time they click a date it'll change colour representing a Day, night or willing to both night and day.

    So far code wise my VBA/SQl seems to work fine accept for a just few of certain dates in the calendar (such as January 2-12th), which is the part that is driving me nuts as I can't figure out why it behaves this way, So if I choose Jan 2nd through 7th it'll give me a message saying about to update (0) rows,and I have no clue as to why as all other dates work fine..Can anyone throw some light as to why this is happening

    I'd pull my hair out (but aint got any left unfortunately.)
    Please see the attached cut down version for test purposes

    Many thanks Gerry From Australia
    Attached Files Attached Files

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    I haven't looked at your database but the clue is in the dates Jan 1st-12th.
    You will have the same problem for the first 12 days of each month ....

    For SQL, dates must be in US format mm/dd/yyyy

    If you have a date in dd/mm/yyyy format such as 03/01/2018 , it will be wrongly interpreted as 3rd March etc
    However, 13/01/2018 can't be anything other than 13 Jan so Access gets that right!

    So you get some correct dates & other incorrect dates !!!

    So change your SQL code to something like Format(MyDateField, "mm/dd/yyyy")
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116
    Quote Originally Posted by ridders52 View Post
    I haven't looked at your database but the clue is in the dates Jan 1st-12th.
    You will have the same problem for the first 12 days of each month ....

    For SQL, dates must be in US format mm/dd/yyyy

    If you have a date in dd/mm/yyyy format such as 03/01/2018 , it will be wrongly interpreted as 3rd March etc
    However, 13/01/2018 can't be anything other than 13 Jan so Access gets that right!

    So you get some correct dates & other incorrect dates !!!

    So change your SQL code to something like Format(MyDateField, "mm/dd/yyyy")
    Thanks tried as you suggest but still get weird results whether I change all to Format(TDate, "mm/dd/yy") or even find and replace all with Format(TDate, "dd/mm/yy")

    Still doesn't work ,but thanks anyways for taking the time to look

  4. #4
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I had a quick look - you have some fixing to do. This line

    Code:
    Dim TDate, LstAmdDte As Date, C1 As Integer, strSql As String, TypeAttend, RecDetect, PrevVal_TypeAttend
    will not do what you think.

    This will declare TDate, TypeAttend, RecDetect, PrevVal_TypeAttend as Variants.

    What you should have done is something like
    Code:
    Dim TDate as Date 
    Dim LstAmdDte As Date
    Dim C1 As Integer, 
    Dim strSql As String, TypeAttend as String , RecDetect as String, PrevVal_TypeAttend as String
    You have to explicitly declare the type.
    Fix all that first then try compiling the database and fix those issues.
    Then repost the fixed version and I suspect some of your issues will be solved.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    Removed post - forgot you had already posted the db
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116
    Quote Originally Posted by Minty View Post
    I had a quick look - you have some fixing to do. This line

    Code:
    Dim TDate, LstAmdDte As Date, C1 As Integer, strSql As String, TypeAttend, RecDetect, PrevVal_TypeAttend
    will not do what you think.

    This will declare TDate, TypeAttend, RecDetect, PrevVal_TypeAttend as Variants.

    What you should have done is something like
    Code:
    Dim TDate as Date 
    Dim LstAmdDte As Date
    Dim C1 As Integer, 
    Dim strSql As String, TypeAttend as String , RecDetect as String, PrevVal_TypeAttend as String
    You have to explicitly declare the type.
    Fix all that first then try compiling the database and fix those issues.
    Then repost the fixed version and I suspect some of your issues will be solved.
    Thanks. I Finally found the SQL issue and its was as you said the needed USA Date format...I wasn't aware that sql will only insert.update if we use USA format(only) dates are a really common issue and I should have known(you'd think MSwould sort this out so as they are not an issue in the future wouldn't you ,considering how much of a pain it is and the amount of revenue they get each month) , So all credit to you for pointing me in the right area.
    I added amended
    Code:
    TDate = Format(TDate, "mm/dd/yy")
    above the sql insert and it worked a treat...I so happy and relieved many thanks for your suggestions

    Code:
    TDate = Format(TDate, "mm/dd/yy")
    
    MsgBox " this will run an Update because a records already exists in AttendType " & vbNewLine & " so it'll increment"
     strSql = "UPDATE Attend SET"
     strSql = strSql & " Attend.AttType = " & TypeAttend & ","
     strSql = strSql & " Attend.LoggedOnUser = '" & Me![txtUserId] & "',"
      strSql = strSql & " Attend.LastAmendedDate = #" & Format(Now, "mm/dd/yy") & "#,"
      strSql = strSql & " PrevVal_TypeAttend =  " & PrevVal_TypeAttend
      strSql = strSql & " WHERE Attend.AttStudent = " & Me![scrStudent] & " AND"
      strSql = strSql & " Attend.AttDate = #" & TDate & "#;"

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The grandfather of all Access developers, Allen Browne, also from 'down under,' (Perth, I believe) has an excellent article on this subject:

    International Dates in Access

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 4
    Last Post: 05-30-2016, 10:53 AM
  2. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  3. Can't Figure out Type Data Mismatch error
    By Caplan1269 in forum Programming
    Replies: 6
    Last Post: 03-06-2013, 11:55 AM
  4. Replies: 0
    Last Post: 10-03-2012, 06:20 AM
  5. Function returning Error 91 (can't Figure out)
    By FrustratedAlso in forum Access
    Replies: 2
    Last Post: 04-17-2012, 02:55 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