Results 1 to 13 of 13
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

    Any comments will be helpful

    Thanks, John

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    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>

    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 :
    Francois

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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)))
    Francois

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    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. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    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. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.
    Francois

  9. #9
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    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. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    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".
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  11. #11
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    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. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Hi All

    Thanks for your help.

    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. #13
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    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.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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