Limit decimal to .0,.25,.50, or .75

hzeigler4

Registered User.
Local time
Yesterday, 20:24
Joined
Apr 18, 2007
Messages
42
I want to force the user to only enter hours in these amounts. For example: have a textbox on a form called hours worked. If the employee worked 4.33 hours the user must enter in 4.50 hours instead. I do not want to except any decimal values other than those listed abouve. Anyone know how?
 
There are several ways to skin this cat. Here's one way I did it in one of my systems:
Code:
Private Sub txtHours_BeforeUpdate(Cancel As Integer)
Dim MyArray As Variant
'-- Test for clearing this TextBox

If Not IsNumeric(Me.txtHours) Then
    Me.Undo
    Cancel = True
Else
    If Me.txtHours <> Int(Me.txtHours) Then
        '-- There is a fractional component.  Make sure it is divisible by .25
        MyArray = Split(CStr((Me.txtHours)), ".")
        If Len(MyArray(1)) = 1 Then
            MyArray(1) = MyArray(1) & "0"   '-- Pad out to 2 places
        ElseIf Len(MyArray(1)) > 2 Then
            MyArray(1) = Left(MyArray(1), 2) '-- Truncate to 2 places
        End If
        If Val(MyArray(1)) Mod 25 Then
            MsgBox "Entry must be in 1/4 hour increments!"
            Cancel = True
        End If
    End If
End If

End Sub
 
Or have a combobox with the segments you want, then force them to pick from the list.
 
Awesome Rural guy!!! Works like a charm and the code is so simple!!! All seems clear to me now!
 

Users who are viewing this thread

Back
Top Bottom