This piece of code was posted on anothers post as a way to use the updown control. I am trying to use the updown control to select a time, but when the time reaches 12 midnite...i get the date and time. Any help or comments would be great. Thanks
Private Sub Form_Load()
TxtTime = Format$(Time, "hh:mm AM/PM"
'time format 12:00 AM or PM
End Sub
'This is a procedure to be called in the UpClick and DownClick
Sub gTimeEditSpin(controlName As TextBox, UpDown As Integer)
'Dim cdate As String
Dim curPos As Integer
Dim selLen As Integer
Dim Interval As String
Dim formatToUse As String
curPos = controlName.SelStart
selLen = 2
On Error GoTo ErrorRtn
Select Case curPos
Case 0, 1 'Hour
Interval = "h"
curPos = 0
Case 3, 4
Interval = "n"
curPos = 3
Case 6, 7
Interval = "s"
curPos = 6
Case Else
Interval = "None"
End Select
If Interval <> "None" Then
controlName.Text = Format$(DateAdd(Interval, UpDown, controlName.Text)) 'Interval, UpDown, CVDate(cdate)), gTimeFormat)
controlName.SelStart = curPos
End If
Exit Sub
ErrorRtn: 'On invalid date/time, exit routine
MsgBox "Invalid date or time - please retype.", 64
Exit Sub
End Sub 'gDateTimeEditSpin --------------------------
Private Sub UpDown1_DownClick()
Call gTimeEditSpin(TxtTime, -1)
End Sub
Private Sub UpDown1_UpClick()
Call gTimeEditSpin(TxtTime, 1)
End Sub
Private Sub Form_Load()
TxtTime = Format$(Time, "hh:mm AM/PM"
End Sub
'This is a procedure to be called in the UpClick and DownClick
Sub gTimeEditSpin(controlName As TextBox, UpDown As Integer)
'Dim cdate As String
Dim curPos As Integer
Dim selLen As Integer
Dim Interval As String
Dim formatToUse As String
curPos = controlName.SelStart
selLen = 2
On Error GoTo ErrorRtn
Select Case curPos
Case 0, 1 'Hour
Interval = "h"
curPos = 0
Case 3, 4
Interval = "n"
curPos = 3
Case 6, 7
Interval = "s"
curPos = 6
Case Else
Interval = "None"
End Select
If Interval <> "None" Then
controlName.Text = Format$(DateAdd(Interval, UpDown, controlName.Text)) 'Interval, UpDown, CVDate(cdate)), gTimeFormat)
controlName.SelStart = curPos
End If
Exit Sub
ErrorRtn: 'On invalid date/time, exit routine
MsgBox "Invalid date or time - please retype.", 64
Exit Sub
End Sub 'gDateTimeEditSpin --------------------------
Private Sub UpDown1_DownClick()
Call gTimeEditSpin(TxtTime, -1)
End Sub
Private Sub UpDown1_UpClick()
Call gTimeEditSpin(TxtTime, 1)
End Sub