Results 1 to 9 of 9
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Have I missed something with date formatting?

    I have a form with a date field



    the command button from anther form has criteria

    DoCmd.OpenForm "frmBookingEditAdminStep", , , "BookingDate between#" & Format(Me.txtFrom, "dd\/mm\/yyyy") & "# and #" & Format(Me.txtUntil, "dd\/mm\/yyyy") & "# and StatusID<>5"

    however I am getting dates 16/1/2013 instead of just dates 16/11/2013 - it's pulling dates in January - how do I avoid this??

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Dates in VBA need to be in US format.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    Dates in VBA need to be in US format.
    I need the dates in Australian (dd/mm/yyyy)

    when you say they need to be in us format - if I put 1/1/2013 until 1/12/2013 then I only get January as apposed to if I put 1/1/2013 until 30/12/2013 I get the whole year

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Aside from this madness (which cannot be turned off), just remember the user interface in Access uses the local Control Panel settings to interpret dates typed into the user interface.
    sigh


  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I guess my next question is aside from making my regional settings setup in the windows control panel (already set) how should I handle dates?

    If I have a field set in dd/mm/yyyy and access swaps it even though I have format(datefield,"dd/mm/yyyy) then how do I handle it so that it gives me the correct filter?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Ruegen View Post
    I need the dates in Australian (dd/mm/yyyy)

    when you say they need to be in us format - if I put 1/1/2013 until 1/12/2013 then I only get January as apposed to if I put 1/1/2013 until 30/12/2013 I get the whole year
    Apples and oranges. What if you use 1/1/2013 and 12/30/2013? Bottom line as I said, in VBA you have to use US format.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Remember that date formatting is for display purposes (screen or print), or input mask only. These settings do not affect how MS Access stores dates.

    Microsoft likes to assume that the whole world uses the illogical date format mm/dd/yyyy, and that's what you need to use in VBA. In your case, though, it is a simple fix. Change the statement in your original post from this:

    DoCmd.OpenForm "frmBookingEditAdminStep", , , "BookingDate between#" & Format(Me.txtFrom, "dd\/mm\/yyyy") & "# and #" & Format(Me.txtUntil, "dd\/mm\/yyyy") & "# and StatusID<>5"

    to this:

    DoCmd.OpenForm "frmBookingEditAdminStep", , , "BookingDate between#" & Format(Me.txtFrom, "mm/dd/yyyy") & "# and #" & Format(Me.txtUntil, "mm/dd/yyyy") & "# and StatusID<>5"


    All I did was change the format of the date in the text string - no changes in the data are needed.

    HTH

    John

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by John_G View Post
    Hi -

    Remember that date formatting is for display purposes (screen or print), or input mask only. These settings do not affect how MS Access stores dates.

    Microsoft likes to assume that the whole world uses the illogical date format mm/dd/yyyy, and that's what you need to use in VBA. In your case, though, it is a simple fix. Change the statement in your original post from this:

    DoCmd.OpenForm "frmBookingEditAdminStep", , , "BookingDate between#" & Format(Me.txtFrom, "dd\/mm\/yyyy") & "# and #" & Format(Me.txtUntil, "dd\/mm\/yyyy") & "# and StatusID<>5"

    to this:

    DoCmd.OpenForm "frmBookingEditAdminStep", , , "BookingDate between#" & Format(Me.txtFrom, "mm/dd/yyyy") & "# and #" & Format(Me.txtUntil, "mm/dd/yyyy") & "# and StatusID<>5"


    All I did was change the format of the date in the text string - no changes in the data are needed.

    HTH

    John
    Thanks John,

    I've got formatting on the text fields on forms as dd/mm/yyyy so I assume access will take dd/mm/yyyy and swap it to mm/dd/yyyy with the formatting and then process it correctly. I think this has fixed my problem.

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

Similar Threads

  1. What is missed in this 'Dcount'? please
    By clebergyn in forum Programming
    Replies: 7
    Last Post: 12-11-2012, 04:28 PM
  2. Date Conditional Formatting
    By f15avionics in forum Access
    Replies: 3
    Last Post: 09-21-2012, 04:45 AM
  3. Date and Time Formatting
    By reidn in forum Access
    Replies: 8
    Last Post: 07-22-2011, 10:18 AM
  4. Formatting a date
    By NISMOJim in forum Queries
    Replies: 7
    Last Post: 09-17-2010, 05:44 PM
  5. Warning Message for Missed Date
    By maintt in forum Access
    Replies: 2
    Last Post: 07-23-2010, 09:05 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