Access - Format textbox AS DATE OR TIME ***ONLY***

ironfelix717

Registered User.
Local time
Today, 09:13
Joined
Sep 20, 2019
Messages
193
Greetings,

Simply attempting to format an unbound textbox as either a date or a time only.

A user would rightfully assume that when one formats a textbox as verbatim "Short Date" or "Short Time" in the design mode, the formatting would actually be a "Short Date" only---or a "Short Time"---only.

The behavior exhibited in my case is a full date/time text being displayed when entering the listbox. I need just a date, or just a time displayed - not both when the user happens to click on the textbox. This behavior is unintuitive and assumingly faulty.

Is the only remedy a VBA change event?

Thanks
 
it is Unbound and still showing the Date portions?
 
Hi, thanks for responding.

So further investigation shows that any numerical input in the box doesn't get flagged as a violation of the set format, and consequently remains in the textbox, but becomes hidden upon exit. Hiding text is a great way to confuse people and create data entry errors (y)


EX:
1.) Format is set to "Medium Time"
2.) User enters box, types a full date and time "11/22/21 4:50am"
3. Exits box
4.) 4:50am is displayed.
5.) Re-Enters box, "11/22/21 4:50am" is displayed.


Set to "Medium Time":

giffy.gif
 
How about on the exit event of the control
me.TxtBoxName = timevalue(me.txtboxname)
 
In case you do not already know this the date and time is a number where the integer portion represents how many days since the base date (Dec 30 1899) and the decimal is the fraction of a day.
Your date
?cdbl(#11/22/21 4:50 AM#)

44522.2013888889

44,522 days since 12/30/1899
and .201... of a whole day. When you take the time value it simply sets the integer to 0
0.2013888889
So really that is 12/30/1899 4:50 AM, but access usually does not display the base date. But actually it is still there also. If you change it then back to long date it will display December 30 1899

IF you take the int you get
44522.0 which is the date 11/22/21 with no fraction of a day
 
Just a thought... If you only want to enter the time portion, have you considered using an Input Mask?
 
The control will obey the Format property and show only the date or the time. However, when you click into the control to edit it, it shows the ACTUAL value.

MajP explained how the date/time data is actually stored.

If you are willing to give up using the date picker, you can use an input mask and that may solve your problem.
 

Users who are viewing this thread

Back
Top Bottom