Home > Software engineering >  Need a proper input mask for a time field in Microsoft Access
Need a proper input mask for a time field in Microsoft Access

Time:12-12

My table field is date/time and formatted like this:

mm/dd/yyyy hh:nn:ss

I want the user to see this (with the space appearing between date and time

__/__/__ __:__:__

I want an input mask that demands:

  • Either 1 or 2 digits for the month
  • Either 1 or 2 digits for the dat
  • All 4 digits for the year
  • SHOWS the space but just jumps over it for the user
  • Either 1 or 2 digits for each of Hours, Minutes and Seconds

Further, when setting up a DB, is it just smarter to have two separate fields for Date and Time. A collegue encouraged me to break them out ... seems sensible?

CodePudding user response:

Controlled user input is not an easy task in Access, as it is optimised for the opposite: To be tolerant and accept many input sequences for date and time.

For the cases where controlled input is mandatory, I've written two articles including full code (too much to post here) and demo, that may give you some ideas:

enter image description here

  • Related