Restrict the Time value entered in a text box

J

Jose

I am having a test box for start time formated in medium time ( i.e.
00:00 AM). How can i restict the time entered by a user so that he/she
should be able to enter the time between 07:00 AM to 03:30 PM.

Thnaks in advance
 
A

Allen Browne

Cancel the BeforeUpdate event procedure of the text box if the time is
outside the range.

Example:

Private Sub Time1_BeforeUpdate(Cancel As Integer)
With Me.Time1
If Not IsNull(.Value) Then
If TimeValue(.Value) < #7:00:00# Or TimeValue(.Value) >
#15:00:00#) Then
Cancel = True
MsgBox "Time1 must be between 7:00 AM to 3:30 PM."
End If
End If
End Sub
End Sub
 
Top