Text box validation rule

C

Charles Tam

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
 
M

Mark

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 ...
 
C

Charles Tam

Hi Mark

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

Kind Regards
Charles
 
G

Graham Mandeno

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top