Setting am/pm as default for time field

  • Thread starter Thread starter Guest
  • Start date Start date
You could set the format of the table field to hh:nn AM/PM, or you could set
the time to a default value and apply the same formatting to the text box on
a form or report in which the value is displayed. What exactly are you
trying to do?
Help has more information on Format Date and Time Values.
 
Oops, I spoke too soon - just realized it doesn't let me edit the Am or Pm,
so it's not a default but is set in stone. I need to be able to change it.
 
Place "hh:nn AM/PM" (without the quotes) into either the table field's
Format property or the Format property for a text box that is bound to the
field containing the time value. If you type "7:00" it will read "7:00 AM".
If you type "13:00" or "1:00 p" it will read "1:00 PM". I usually apply the
format to the text box rather than to the table field, but I don't know if
it matters.
Leave out the quotes when typing the test values I have suggested.
 
It has been a bit difficult figuring out what you need to do. Sometimes it
helps to describe in non-database terms the result you are seeking. For
instance, "default" has a specific meaning that you apparently did not
intend.
What I suggested was the Format property. You need to enter the characters
exactly as I have shown you in the Format property. There is also a
property called Input Mask, which controls how the data are entered. You
could use something like:
00:00\ >??;0;_
This means the four-digit time is required (e.g. 07:30). The ">" converts
the letters (AM or PM) to uppercase. The question marks mean "AM" or "PM"
are optional. If you leave them out, Access assumes a 24-hour clock, so
07:30 defaults to AM, and 12:30 defaults to PM. 00:30 is 12:30 AM.
You do not need to type the colon. If you type 0730, you are entering 7:30
AM. 1230a becomes 12:30 AM; 0130p is 1:30 PM.
The 0 after the semi-colon means the display characters are stored; a 1
means they are not. Since this is happening in a Date/Time field I don't
think it matters which you use.
The underscore at the end of the Input Mask means the user sees _ as a
placeholder for each character.
You could use 99:00\ >??;0;_ or 90:00\ >??;0;_as the input mask. The 9
characters mean entry is optional, but this mean the user needs to use the
arrow key or the mouse to get to the second character when entering 730 for
7:30 AM, so you may as well use the first example.
There is more information in Help (although it seems to lack the information
about the semi-colons in the mask, at least in Access 2003).
 
Not meaning to be vague - it's just a little time card entry where the start
time is typically am and end is pm. The format you suggested is great for
the am but requires them to use the 24 hour clock for the pm and they are
resistant to that. Would like to enter 0400 and have it interpreted as 04:00
pm for end time - that's what I mean by combining default value and input
mask.
 
You could use the After Update event for the EndTime text box, maybe
something like:

If Not IsNull(Me.EndTime) Then
If Hour(Me.EndTime) < 12 Then
Me.EndTime = DateAdd("h", 12, Me.EndTime)
End If
End If

If you want to allow for the possibility of an AM time as the EndTime, you
could add an unbound check box (chkAM) for those occasions. The check box
would default to False. The After Update could be something like:

If Not IsNull(Me.EndTime) Then
If Me.chkAM = False Then
If Hour(Me.EndTime) < 12 Then
Me.EndTime = DateAdd("h", 12, Me.EndTime)
End If
End If
End If

The StartTime text box may need something similar if the StartTime is ever
in the afternoon or evening.

Or you could try to train users to add the letter "p" after entering PM
hours (or "a" for AM hours before 1:00 AM, if that ever comes up).
 
Thank you for all your help on this, Bruce. Your suggestions are greatly
appreciated and I'll probably go with something like you suggested here so
that they only have to act on the a or p if it's an exception to the rule.
Much obliged.
 
Back
Top