Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can someone please explain what is wrong with this code???

Status
Not open for further replies.

jh508

Technical User
Mar 26, 2001
8
0
0
US
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 <> &quot;None&quot; 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 &quot;Invalid date or time - please retype.&quot;, 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
 
DateAdd function returns a date value
if you want a time, try this:

controlName.Text = Format$(DateAdd(Interval, UpDown, controlName.Text),&quot;Long Time&quot;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top