date format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I format a time as hh:nn but have it display 2:00 for 2 pm rather than
14:00 without showing the AM or PM?
 
Yes, in form design view set the textbox' Format property to Medium Time.

Sprinks
 
Can I format a time as hh:nn but have it display 2:00 for 2 pm rather than
14:00 without showing the AM or PM?

So you're comfortable with 7:00 being maybe first thing in the
morning, maybe staying late in the evening, leaving it up to the
viewer to guess which is meant??

John W. Vinson[MVP]
 
this is for office hours running from 8:00 am to 4 pm with no ambiguous times
(no 7 am or 7 pm) and just a personal preferance. I can live with AM and PM.
 
smk23 said:
this is for office hours running from 8:00 am to 4 pm with no
ambiguous times (no 7 am or 7 pm) and just a personal preferance. I
can live with AM and PM.

=Left(Format([DateTimeField], "h:nn ampm"), Len(Format([DateTimeField],
"h:nn ampm"))-3)
 
SMK,

Sorry; I misread your question.

Although it's a bit of work, you can do what you want (sort of) by setting
the ControlSource of a textbox to:

=IIf(Hour([YourTimeFld])>=12,DateAdd("h",-12,[YourTimeFld]),[YourTimeFld])

Lay the textbox directly over one bound to your field. Set the latter's
Visible property to No in design view, and the other's to Yes. By default
then, the form will display the value formatted as you wish, albeit in a
control that is non-editable.

If you wish to be able to edit the field, you can use the Enter event of the
calculated control and the Exit event of the Bound control to toggle the
Visibility (and therefore, editability) of the two controls:

' Calculated Control Enter event code
With Me![YourBoundControl]
.Visible = True
.SetFocus
End With
Me![YourCalculatedControl].Visible = False

' Bound Control Exit event code
Me![YourCalculatedControl].Visible = True
' Set focus to next form control, since you're finished editing
Me![YourNextControl].SetFocus
Me![YourBoundControl].Visible = False

Hope that helps.
Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top