Testing numeric input

L

Luciano

Is there a way to prevent input a Text-when the field requires a numeric input?
Perhaps there is a function that test the input-type?
Something like:

Sub txtField_BeforeUpdate
if "txtField is not Numeric" then
MsgBox "Please give a number"
SendKeys "{esc}"
Cancel = True
end if
End Sub
 
T

Tom van Stiphout

On Thu, 3 Jun 2010 04:18:11 -0700, Luciano <[email protected]>
wrote:

There is of course the IsNumeric function.
But I typically let Access deal with data type issues: just define the
fields in the tables correctly, and use bound forms. Access will
complain if the wrong data type is used.

-Tom.
Microsoft Access MVP
 
D

Daniel Pineault

You had the concept. You can use the IsNumeric() function to test the input
value is a numeric value.

Also, if you setup your table format property... when the user input the
wrong data format they will automatically be notified.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
M

Marshall Barton

Luciano said:
Is there a way to prevent input a Text-when the field requires a numeric input?
Perhaps there is a function that test the input-type?
Something like:

Sub txtField_BeforeUpdate
if "txtField is not Numeric" then
MsgBox "Please give a number"
SendKeys "{esc}"
Cancel = True
end if
End Sub


No code needed. Assuming your numbers are positive
integers, try setting the text box's ValidationRule property
to something like:
Not Like "*[!0-9]*"
and set the ValidationText property to your message.

IMPORTANT NOTE
You should NOT use SendKeys, it has several problems that
can cause weird things such as messing with the NumLock key.
In this case, you would use:
Me.txtfield.Undo
 
L

Luciano

Thank you so much. I did have many times problems with the NumLock (Random
On/Off). So I can modifie some code and hope that it will prevend this
malfunction.

Marshall Barton said:
Luciano said:
Is there a way to prevent input a Text-when the field requires a numeric input?
Perhaps there is a function that test the input-type?
Something like:

Sub txtField_BeforeUpdate
if "txtField is not Numeric" then
MsgBox "Please give a number"
SendKeys "{esc}"
Cancel = True
end if
End Sub


No code needed. Assuming your numbers are positive
integers, try setting the text box's ValidationRule property
to something like:
Not Like "*[!0-9]*"
and set the ValidationText property to your message.

IMPORTANT NOTE
You should NOT use SendKeys, it has several problems that
can cause weird things such as messing with the NumLock key.
In this case, you would use:
Me.txtfield.Undo
 
J

John W. Vinson

Thank you so much. I did have many times problems with the NumLock (Random
On/Off). So I can modifie some code and hope that it will prevend this
malfunction.

Just a note - there's a longstanding bug in Access, that causes the NumLock
setting to change unpredictably if you use the "SendKeys" action in VBA or in
a macro. Check your code to see if SendKeys is being used; it's never required
and has in fact been removed from the most recent versions.
 

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