How to set the format for a field so user must enter time is a certain format?
PROBLEM
How to set the format for the fields “Sampling Start Time” and “End Start Time” so the user must enter the time in this format “3:30 PM” or “3:30 AM”. (See attached image.)
Format is the way data looks ... not what it IS ... Format can give clues, and trigger other behaviors. It may be good to set the format property to one of the named time formats, or enter a custom format when a Time is expected. However, this will not stop the user from entering something that is not a valid time.
~~~
to answer your question:
To ensure data can be understood as a Time before allowing the user to leave the control, here are a couple ways:
1. InputMask might seem to be the easy choice ... however, there are reasons I would not set it for date/time ... for instance, to use shortcuts like 8a (8:00 am), and 2p (2:00 pm).
2. validate data using form BeforeUpdate event, and/or control BeforeUpdate event
check the value that the user inputs before it is saved. If you are new to VBA and need an example, please let us know.
thanks
have an awesome day,
crystal
cssc1
ASKER
Yes, I am new to vba, an example would help
crystal (strive4peace) - Microsoft MVP, Access
actually, you don't need VBA in this case, since the controls are bound to fields. In the design view of the tblSilica1 table, the data type of [Sampling Start Time] and [Sampling End Time] should be Date/Time, not Short Text.
Internally, Date/Time stores values as numbers; the whole part of the number represents days passed since 12/30/1899; the fractional part of the number represents time.
0.5 is noon -- halfway through the day
0.75 is 6:00 pm
Format is the way data looks ... not what it IS ... Format can give clues, and trigger other behaviors. It may be good to set the format property to one of the named time formats, or enter a custom format when a Time is expected. However, this will not stop the user from entering something that is not a valid time.
~~~
to answer your question:
To ensure data can be understood as a Time before allowing the user to leave the control, here are a couple ways:
1. InputMask might seem to be the easy choice ... however, there are reasons I would not set it for date/time ... for instance, to use shortcuts like 8a (8:00 am), and 2p (2:00 pm).
2. validate data using form BeforeUpdate event, and/or control BeforeUpdate event
check the value that the user inputs before it is saved. If you are new to VBA and need an example, please let us know.
thanks
have an awesome day,
crystal