Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access 2016 date picker changing date format

Posted on 2016-08-31
6
Medium Priority
?
686 Views
Last Modified: 2016-10-07
I am running Access 2016 in Windows 10.  I have a form with a text box that displays dates.  It is set to show the date picker.  The text box Format property is set to Long Date. In the Load event for the form, the text box is set to Format(Now(), "Long Date") and all displays well when it first opens.  However, when I use the date picker to select a date, it displays as the correct long date but the Me.textbox.value property has the date in a dd/mm/yyyy format.  This causes a problem when I use this value for a date comparison with database table dates that are stored in a date field, which compare as mm/dd/yyyy.  If I pick today's date to find in the database, the database date will be 08/31/2016 and the me.textbox.value will be 03/08/2016.  I determined this in debug mode.

I tried Format(Me.textbox.value, "mm/dd/yyyy") but still got 03/08/2016.  The only way to get the right date is Format(Me.textbox.value, "dd/mm/yyyy")!  That gives me 08/31/2016, which is crazy.

What is going on here?

Thanks.
0
Comment
Question by:McLeanIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41778251
What does the format specification of "dd-Mmm-yyyy" produce?
0
 
LVL 39

Accepted Solution

by:
PatHartman earned 1000 total points (awarded by participants)
ID: 41778303
STOP formatting the dates.  Once you format a date, it becomes a text field and then it acts like a text field rather than like a date field.  Dates are stored internally as double precision numbers.  The integer part is the number of days since Dec 30, 1899 and the decimal is the fraction of the day since midnight.

As long as you don't use the Format() function, your dates will stay as DateTime data type and compares will work as you expect.

Use the format property of the control to specify how the date should be formatted for human viewing.

print now()
8/31/2016 11:48:59 AM
print cdbl(#8/31/2016 11:48:59 AM#)
 42613.492349537
print DateAdd("d", 42613, #12/30/1899#)
8/31/2016

The cdbl() version is how the date is stored internally.  Dates are stored this way because it makes arithmetic and logical operations simpler and does not require Access to do a lot of conversions behind the scenes.
0
 
LVL 51

Assisted Solution

by:Gustav Brock
Gustav Brock earned 500 total points (awarded by participants)
ID: 41778710
In the Load event for the form, the text box is set to Format(Now(), "Long Date")
Then you convert the date value to a string.
So set the value to a date value:

    Me!textbox.Value = Now

or, as you don't need the time, rather:

    Me!textbox.Value = Date

/gustav
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
LVL 22

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points (awarded by participants)
ID: 41780414
adding on to Pat's comment:
the Format function always returns a string (which is text) and no longer a date/time data type

and repeating: to retain the date/time data type, use the Format PROPERTY to change the display, not the Format function
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41800508
The questioneer is non-responding, so I vote for a delete.

/gustav
0
 
LVL 22
ID: 41833315
poster seems to have issues with data type
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question