Access - Format textbox AS DATE OR TIME ***ONLY*** (1 Viewer)

ironfelix717

Registered User.
Local time
Yesterday, 20:17
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:17
Joined
May 7, 2009
Messages
19,237
it is Unbound and still showing the Date portions?
 

ironfelix717

Registered User.
Local time
Yesterday, 20:17
Joined
Sep 20, 2019
Messages
193
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
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:17
Joined
May 21, 2018
Messages
8,527
How about on the exit event of the control
me.TxtBoxName = timevalue(me.txtboxname)
 

ironfelix717

Registered User.
Local time
Yesterday, 20:17
Joined
Sep 20, 2019
Messages
193
@MajP

I guess that is what is required to truly "format" this textbox.

Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:17
Joined
May 21, 2018
Messages
8,527
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:17
Joined
Oct 29, 2018
Messages
21,469
Just a thought... If you only want to enter the time portion, have you considered using an Input Mask?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:17
Joined
May 21, 2018
Messages
8,527
Here is a time picker control if you want.
TP.jpg
 

Attachments

  • MajP Option Time Picker.accdb
    1.8 MB · Views: 284

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:17
Joined
Feb 19, 2002
Messages
43,266
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

Top Bottom