Help with Time

  • Thread starter Thread starter Rick Conover
  • Start date Start date
R

Rick Conover

I have the following field:

fldStartTime
Format = Short Time
Input Mask = 00\:00;0;"_"

I would like the user only to be able to put in the
minutes as XX:00, XX:15, XX:30, or XX:45 (top of the
hour, quarter hour, half hour or three quarter hour).

If the user inserts anything other than the quarter hour
(i.e., XX:12), then a message box saying that they can
only enter quarter hour increments needs to warn the user.

I tried using Left([fldStartTime]), 4) but it does not
work.

Any help on code for the Before Update event procedure
would be appreciated.

Rick
 
Unless you have some custom code to do your field specific validation
checks, why not use the BeforeUpdate Event to check this out?

The code you can use is the following:

Select Case Minute(Me.fldStartTime.Value)
Case 0,15,30,45
Case Else
Msgbox "You must put in the minute as '00', '15', '30', or
'45'.",48)
Cancel = -1
End Select

This is how must developers does it. I have my own custom code for specific
field level validation checks cause the way the events works in Access, it's
not quite so user friendly for the predominantly mouse users, cause it's not
100% of the time you want the exact same validation checks to take place for
whenever the field is about to lose it's focus. However, even in my custom
Validate Event, I still would use the above code in that Event.

Example: If a user clicks on a command button to back out of the form, get
help, or reset the form, in each of these 3 situations, you wouldn't want to
have the above validation code ran, but cause of how Access Events are
setup, with the above code in the BeforeUpdate Event of the control, the
code behind the command button would not ever get ran, should the Cancel
variable in the BeforeUpdate Event get set to either True or -1. This is
the very reason why I have created my own custom code to similate the VB6
CausesValidation Property and Validate Event. However, in the absence of
the custom validation code, you would use the BeforeUpdate Event to do the
validation check. Of course, my custom validation code only works on
unbound forms.
 
Well I would think that using the Left([fldStartTime]), 4)
would result in the following: "12:3"
Maybe try something like this:

Dim varStart as Variant
varStart = Right([fldStartTime],2)
If varStart <> 00 AND _
varStart <> 15 AND _
varStart <> 30 AND _
varStart <> 45 Then
Msgbox "You can only enter quarter hour " & _
"increments.", vbExclamation, "Invalid Time"
End If
 
Back
Top