# Thread: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

1. ## Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Print Medium Time w/o AM or PM?

A2k (9.0.3821) SR-1

I have a time field defined as medium time 12:45 AM

I need to print the time only 12:45 in a preprinted box on a form as 12:45
and the A or P in one of two other text boxes as A or P

What is the best way to print the 12:45 only in a text box?

What is the best way to compare for AM or PM and print an A or B in another text box?

Thanks, John

2. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

To print the time only, your controlsource needs to be:<pre> =Left( format(yourfield,"hh:nnAM/PM"),4)</pre>

To print only A or P, use:<pre> =Left( format(yourfield,"AM/PM"), 1)</pre>

3. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Left( format(yourfield,"hh:nnAM/PM"),4)
should be
Left( format(yourfield,"hh:nnAM/PM"),5)
Mark forget to count the :

4. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Hi Mark & Francois

I caught that, Thanks for your code.

Here is one more:

=Right([strRegNo],5)

this print 00123

What kind of format command do I wrap around this to eliminate the zeros and print 123

Thank, John

5. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

If your string contain only numbers :
= Trim(Val(Right([strRegNo],5)))

6. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Mark,

Wouldn't the following work?

Format(yourfield,"hh:nn")

Cheers,
Pat

7. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Francois,

Why do you need the Trim around the expression? Wouldn't just the following work?

=Val(Right([strRegNo,5]))

Cheers,
Pat

8. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

This would work if you agree to have one space before the number. When you use val you have a space before the number for a positive number and a - for a negative number.

9. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Thanks Francois, that goes way back to the GWBasic days.

10. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

You wrote:

Wouldn't the following work?

Format(yourfield,"hh:nn")

It will work fine if "yourfield" has a value before 1PM. Starting then, however, instead of "01:00", you will see "13:00".

11. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Well done Mark, I obviously hadn't thought of that one.
One learns a lot on this forum.
Thanks
Pat

12. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

Hi All

For your Access grabbag, following are other suggestive solutions I picked up on other forums, howevre no tested.

Well, if you use a Format of hh:nn, you'll get "military" time. I suppose
you could do something like:

=IIF(Format([TimeField], "hh") >= "13", Format([TimeField] - #12:00#,
"hh:nn"), Format([TimeField], "hh:nn")

For the "A" or "P" text boxes, use:

=IIF([TimeField] >= #12:00#, "P", "A")

John

13. ## Re: Print Medium Time w/o AM or PM? (A2k (9.0.3821) SR-1)

My understanding is that IIF is one of the poorer performance functions, and this might be a factor with large recordsets. On reason is that all 3 parts of the function are processed. So when you have:<pre>=IIF(Format([TimeField], "hh") >= "13", Format([TimeField] - #12:00#,
"hh:nn"), Format([TimeField], "hh:nn")</pre>

Access actually has to evaluate all 3 Format functions, then pass the results to the function, which makes the decision then returns the correct value.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•