Results 1 to 10 of 10
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Date Format issue switching Region

    Hi,

    I created an access database 5 years ago i Sweden. Now, a person in Finland wants to run the program and that created error. I switched Region in control panel on my computer to Finland from Sweden. Now I get the same error.

    In Finland they give Date in format "d.m.yyyy'. In tables inside my access database, Dates are written like '17.11.2023'. If I write my WHERE clause in SQL code using #17.11.2023# creates an error. However, using #17/11/2023# is working. There seems to be a mix of date format using Region = Finland.



    Has anyone any idea what's happening?

    I just made a test by using function CDate using Region = Finland:

    CDate("17.11.2023") = 17.11.2023
    CDate("17/11/2023") = 17.11.2023

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Try using a different format #yyyy-mm-dd#

    2023-11-17

    As far as I am aware this is unambiguous and works everywhere.
    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 ↓↓

  3. #3
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    We are using "yyyy-mm-dd" is Sweden. Probably why it has been working without any issue because it's only Swedish people who has used the program.

    However, it's just so boring to tell the user in Finland to use "yyyy-mm-dd" just to run this application, when they use "d.m.yyyy" everywhere else.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    You don't (shouldn't) need to get the user to adjust, on forms it should accept the windows locale defaults inputs
    It's only if you write a SQL statement in VBA it will (could) have an issue.
    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
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    OK. I use a lot of SQL Statement in VBA code in this application.

    Thanks for your help.

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    I'm probably teaching grandma to suck eggs but use a function to do the hard work: Simply pass in the form value SQLDate(Me.MyDateControl)
    I have an similar function for passing dates to SQL Server so adds the single quotes required in the server.
    Code:
    Function SQLDate(varDate As Variant) As String
        'Purpose:    Return a delimited string in the date format used natively by JET SQL.
        'Argument:   A date/time value.
        'Note:       Returns just the date format if the argument has no time component,
        '                or a date/time format if it does.
        'Author:     Allen Browne. allen@allenbrowne.com, June 2006.
        'Adjusted Minty 2013 - to a more universal format
        
        If IsDate(varDate) Then
            If DateValue(varDate) = varDate Then
                SQLDate = Format$(varDate, "\#yyyy-mm-dd\#")
            Else
                SQLDate = Format$(varDate, "\#yyyy-mm-dd hh\:nn\:ss\#")
            End If
        End If
    End Function
    in the immediate window;
    ?sqldate (date())
    #2023-04-02#
    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 ↓↓

  7. #7
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    That is good tip.

    Thanks!

  8. #8
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    There is an side benefit to using this - when you are debugging, the date in this format is unambiguous to the eye as well.
    No wondering if it mm/dd/yyyy or dd/mm/yyyy or if it's converted or not. Makes things much more obvious.
    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 ↓↓

  9. #9
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    I replaced

    dteMy

    with

    Format(dteMy, ”YYYY-MM-DD”)

    after WHERE in my SQL in VBA code. Now it’s working.

    Thanks again.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You still need the # though, surely. ?
    Plus be aware Format() converts it to a string?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Date format issue
    By dollygg in forum Programming
    Replies: 1
    Last Post: 12-24-2022, 12:50 PM
  2. Replies: 0
    Last Post: 05-08-2020, 04:54 AM
  3. Date format issue
    By di.miller in forum Queries
    Replies: 3
    Last Post: 03-17-2011, 09:36 AM
  4. American/European date format issue
    By dantnz in forum Programming
    Replies: 2
    Last Post: 12-09-2010, 03:17 PM
  5. Field switching from Number format to Text
    By COforlife in forum Queries
    Replies: 1
    Last Post: 11-10-2009, 03:23 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