Results 1 to 6 of 6

Thread: Time field

  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am working on a database that keeps track of each time a student is tardy to school. When the time is entered into a field which has it's format set to hh:nn am/pm. I would like the am or pm to be automatic so that entries greater than 6:00 and less that 11:59 would be am. All other entries would be pm. Is there a way to accomplish this?
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    It would be easiest if the users would enter times using the 24 hour clock. With the format you have chosen, 14:28 will automatically be displayed as 2:28 PM. No code needed.

    Otherwise, you'd need code in the After Update event of the text box bound to the time field. Let's say the text box (or field) is named txtTime:

    Code:
    Private Sub txtTime_AfterUpdate()
      If Me.txtTime < #6:00:00 AM# Then
    	Me.txtTime = Me.txtTime + #12:00:00 PM#
      End If
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help. I think the code would be the way to go. Since the users are not use to using the 24 hour clock, it would be too hard for them to enter time that way.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  4. #4
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='780337' date='18-Jun-2009 02:03']It would be easiest if the users would enter times using the 24 hour clock. With the format you have chosen, 14:28 will automatically be displayed as 2:28 PM. No code needed.

    Otherwise, you'd need code in the After Update event of the text box bound to the time field. Let's say the text box (or field) is named txtTime:

    Code:
    Private Sub txtTime_AfterUpdate()
       If Me.txtTime < #6:00:00 AM# Then
    	 Me.txtTime = Me.txtTime + #12:00:00 PM#
       End If
     End Sub
    [/quote]
    Hi HansV,
    Forgive me for jumping in. May I know what's the underlining logic of being an AfterUpdate event rather than On Lost Focus event?
    Armstrong

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The After Update event occurs only if the user has modified the value of the text box.
    The On Lost Focus event occurs each time the user tabs or clicks out of the text box. So the code would be executed even if the user hasn't changed anything. That is not very efficient.

  6. #6
    3 Star Lounger
    Join Date
    Mar 2009
    Location
    Hong Kong
    Posts
    359
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='780470' date='18-Jun-2009 19:15']The After Update event occurs only if the user has modified the value of the text box.
    The On Lost Focus event occurs each time the user tabs or clicks out of the text box. So the code would be executed even if the user hasn't changed anything. That is not very efficient.[/quote]
    Thanks for your explanation. I select the On Lost event because it "repaints" the modified value instantly.
    Armstrong

Posting Permissions

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