check number is an integer

jattman

New member
Local time
Today, 22:37
Joined
Nov 7, 2004
Messages
8
what's the easiest and best way to check and make sure that the value entered into an input field, on a form, is an integer?
 
j,

Code:
If Int(Me.YourField) = Me.YourField Then
   MsgBox("It's an integer.")
Else
   MsgBox("Not an integer.")
End If

or:

If InStr(1, CStr(Me.YourField), ".") = 0 Then
   MsgBox("It's an integer.")
Else
   MsgBox("Not an integer.")
End If

Wayne
 
if it wouldnt be a hassle could you please explain briefly how the second one works. It works fine so thanks for that but i want to understand how it works aswell. Thanks.
 
j,

From the inside-out, convert your number to a string. If there is not a
decimal point in it (InStr function), then it must be an integer.

InStr(1, CStr(Me.YourField), ".") = 0

Wayne
 

Users who are viewing this thread

Back
Top Bottom