Text box validation rule

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Users,

I would like to configure a text box such that it does not accept decimals
but accept only whole number. Any ideas?

Kind Regards
Charles
 
One option is to go into the table design and set the Data Type to Number,
and the Field Size to one of the following:
Byte: 0 to 255 (no fractions)
Integer: -32,768 to 32,767 (no fractions)
Long Integer: -2,147,483,648 to 2,147,483,647 (no fractions)



"Charles Tam" wrote ...
 
Hi Mark

Thanks for your reply. However, my text box is unbound to data source. Any
other alternatives.

Kind Regards
Charles
 
Hi Charles

Something like this in the BeforeUpdate event should do the trick:

Private Sub Text0_BeforeUpdate(Cancel As Integer)
If IsNumeric(Text0) Then
If Val(Text0) <> Int(Text0) Then Cancel = True
Else
Cancel = True
End If
If Cancel Then
MsgBox "Please enter a whole number", vbExclamation, "Invalid data"
End If
End Sub
 
Back
Top