limiting input on time formatted control

C

Chris

I may not have said that correctly. Here goes...

User inputs time into a field by entering or using KeyPress event to
increase/decrease time in 15 minute increments.
******* code for keypress event
Dim strInterval As String
strInterval = "n"
Select Case KeyAscii
Case 43 'plus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, 15, Screen.ActiveControl)
Case 45 'minus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, -15, Screen.ActiveControl)
End Select
******* end code

My conrtrol [txtDC7Start] is formatted "h:nn a/p" and defaults to "8:00 a".
Its control source is [DC7Start]. Presently, the user can +/- or enter the
time. I want to restrict their input to between 6 am and 10 pm. I am having
trouble with the time format combined with limitation.

Can someone suggest a simple method to accomplish this limitation? The
 
J

John W. Vinson

I may not have said that correctly. Here goes...

User inputs time into a field by entering or using KeyPress event to
increase/decrease time in 15 minute increments.
******* code for keypress event
Dim strInterval As String
strInterval = "n"
Select Case KeyAscii
Case 43 'plus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, 15, Screen.ActiveControl)
Case 45 'minus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, -15, Screen.ActiveControl)
End Select
******* end code

My conrtrol [txtDC7Start] is formatted "h:nn a/p" and defaults to "8:00 a".
Its control source is [DC7Start]. Presently, the user can +/- or enter the
time. I want to restrict their input to between 6 am and 10 pm. I am having
trouble with the time format combined with limitation.

Can someone suggest a simple method to accomplish this limitation? The

The format shouldn't have anything to do with it. If you want to
constrain the result to a range of times, what do you want to happen
when the user gets outside the range?

Try this:

Dim strInterval As String
Dim vTime As Variant
vTime = Timevalue(Screen.ActiveControl)
strInterval = "n"
Select Case KeyAscii
Case 43 'plus key
KeyAscii = 0
If vTime >= #10:00pm# Then
Beep
Else
vTime = DateAdd(strInterval, 15,vTime)
End If
Case 45 'minus key
KeyAscii = 0
If vTime <= #6:00am# Then
Beep
Else
vTime = DateAdd(strInterval, -15, vTime)
End If
End Select
Screen.ActiveControl = vTime

John W. Vinson [MVP]
 
C

Chris

Hmmm...what did I want? What you gave me. Perfecto!

Once again, the gurus come through for the riff raff.

Thanks, John.
--
Chris


John W. Vinson said:
I may not have said that correctly. Here goes...

User inputs time into a field by entering or using KeyPress event to
increase/decrease time in 15 minute increments.
******* code for keypress event
Dim strInterval As String
strInterval = "n"
Select Case KeyAscii
Case 43 'plus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, 15, Screen.ActiveControl)
Case 45 'minus key
KeyAscii = 0
Screen.ActiveControl = DateAdd(strInterval, -15, Screen.ActiveControl)
End Select
******* end code

My conrtrol [txtDC7Start] is formatted "h:nn a/p" and defaults to "8:00 a".
Its control source is [DC7Start]. Presently, the user can +/- or enter the
time. I want to restrict their input to between 6 am and 10 pm. I am having
trouble with the time format combined with limitation.

Can someone suggest a simple method to accomplish this limitation? The

The format shouldn't have anything to do with it. If you want to
constrain the result to a range of times, what do you want to happen
when the user gets outside the range?

Try this:

Dim strInterval As String
Dim vTime As Variant
vTime = Timevalue(Screen.ActiveControl)
strInterval = "n"
Select Case KeyAscii
Case 43 'plus key
KeyAscii = 0
If vTime >= #10:00pm# Then
Beep
Else
vTime = DateAdd(strInterval, 15,vTime)
End If
Case 45 'minus key
KeyAscii = 0
If vTime <= #6:00am# Then
Beep
Else
vTime = DateAdd(strInterval, -15, vTime)
End If
End Select
Screen.ActiveControl = vTime

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top