Problem with "2 decimal places" code

AlanW

Registered User.
Local time
Today, 10:28
Joined
Aug 11, 2001
Messages
25
I have this code which checks that a number entered into a field is no longer than 2 decimal places. This works fine as long as there is a number is the field but when the field is blank (null) it produces an error. I've tried different code to get round this without success. Can someone help?

Private Sub Payment_Amount_BeforeUpdate(Cancel As Integer)

DotLoc = InStrRev(Payment_Amount, ".")
If DotLoc <> 0 And (Len(Me.Payment_Amount) - DotLoc) > 2 Then
MsgBox "This field must be input to no more than two decimal places"
Cancel = True
End If
 
Code:
Private Sub Payment_Amount_BeforeUpdate(Cancel As Integer)

if isnumeric(Payment_AMount) then
   DotLoc = InStrRev(Payment_Amount, ".")
   If DotLoc <> 0 And (Len(Me.Payment_Amount) - DotLoc) > 2 Then
   MsgBox "This field must be input to no more than two decimal places"
   Cancel = True
    End If
else
   msgbox "Enter a number in here please"
end if.
 

Users who are viewing this thread

Back
Top Bottom