Solved

Access 2016 date picker changing date format

Posted on 2016-08-31
6
136 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
6 Comments
 
LVL 35

Expert Comment

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

Accepted Solution

by:
PatHartman earned 250 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 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 19

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 125 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 49

Expert Comment

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

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

820 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