Enter time using 3 combo boxes

AmberO

Registered User.
Local time
Today, 00:56
Joined
May 9, 2002
Messages
27
I would like a user to be able to enter a time using three combo boxes - one for hours, one for minutes and one for am\pm. I would also like the time to be displayed on a search using a similar setup, so that the time could be changed by the user.

What is the best way to approach this? I have managed to get the combo boxes displaying the time in a medium time field correctly, but not writing to the table. But I can't get it to work backwards so that a time stored in a table is displayed using the combos.

Any help would be greatly appreciated.
Thanks in advance,
Amber
 
Is this what you are looking for?

Code:
    Me.cboHours = Format(Me.txtTime, "h")
    Me.cboMinutes = Format(Me.txtTime, "nn")
    Me.cboAmPm = Format(Me.txtTime, "AM/PM")
&
Code:
     Me.txtTime = Format(Me.cboHours & ":" & Me.cboMinutes & " " & Me.cboAmPm, "Medium Time")
________
Pot
 
Last edited:
I'm sure that there must be a better way to do what you want, but have a look at the following anyway... it seems to work!

Rob

Table
Fields - ID: Date: Time

form
TxtID: TxtDate: TxtTime

three combo boxes - CmboHour: CmboMin: ComboAmPm

Code:
Option Compare Database
Option Explicit

Dim hr 'hour
Dim mn 'minute
Dim tm 'time
Dim AmPm 'AM / PM

Private Sub Form_Load()
Dim i

'Populate combo boxes

For i = 1 To 59
CmboMin.AddItem i
If i < 13 Then CmboHour.AddItem i
Next i

CmboAmPm.AddItem "AM"
CmboAmPm.AddItem "PM"
End Sub


Private Sub CmboHour_AfterUpdate()
mn = CmboMin.Value
hr = CmboHour.Value
AmPm = CmboAmPm.Value
    
tm = Format(hr & ":" & mn & " " & AmPm, "medium time")
Me.Time = tm

End Sub

Private Sub CmboMin_AfterUpdate()
mn = CmboMin.Value
hr = CmboHour.Value
AmPm = CmboAmPm.Value
    
tm = Format(hr & ":" & mn & " " & AmPm, "medium time")
Me.Time = tm

End Sub

Private Sub CmboAmPm_AfterUpdate()
mn = CmboMin.Value
hr = CmboHour.Value
AmPm = CmboAmPm.Value
    
tm = Format(hr & ":" & mn & " " & AmPm, "medium time")
Me.Time = tm

End Sub

Private Sub Form_Current()

On Error GoTo Err_Handler

    hr = Hour(Me.Time)
    mn = Minute(Me.Time)
    
    If hr > 12 Then
        AmPm = "PM"
    hr = hr - 12
        Else: AmPm = "AM"
    End If
    
    CmboMin.Value = mn
    CmboHour.Value = hr
    CmboAmPm.Value = AmPm

Exit Sub

Err_Handler:

CmboMin.Value = 0
CmboHour.Value = 12
CmboAmPm.Value = "AM"

End Sub

Rob :)
 
Rob,

Thank you so much, this is exactly what I was looking for!

Amber
 

Users who are viewing this thread

Back
Top Bottom