Solved

Access 2016 date picker changing date format

Posted on 2016-08-31
6
39 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 34

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now