Prevent Text Data being entered into Numeric field Database ...

F

Fred's

Hello,

does anyones knows how can prevent text Data being entered into
numeric field Database.

Thank you for your help!
Fred's
 
P

Peter Hibbs

Fred,

Assuming you are doing this on a form and not a table you can enter
the following code into the KeyPress event of the text box control.

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) Like "[!0-9.]" And KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End Sub

where Text1 is the name of your Text box. This code will only allow
the digits 0-9 and the Period characters to be entered into the box.

If you don't need decimal points omit the . between the square
brackets and if you need negative numbers add a - after the .

HTH

Peter Hibbs.
 
M

Maurice

Hi Fred,

I think, no I know it isn't possible to enter text in a numeric field in a
table. So what you should do if this is possible is to change the datatype of
that field to number. Just my two cents
 
F

Fred's

Fred,

Assuming you are doing this on a form and not a table you can enter
the following code into the KeyPress event of the text box control.

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Chr(KeyAscii) Like "[!0-9.]" And KeyAscii <> vbKeyBack Then      
        KeyAscii = 0
    End If
End Sub

where Text1 is the name of your Text box. This code will only allow
the digits 0-9 and the Period characters to be entered into the box.

If you don't need decimal points omit the . between the square
brackets and if you need negative numbers add a - after the .

HTH

Peter Hibbs.

On Tue, 16 Dec 2008 13:28:30 -0800 (PST), "Fred's"

Hello Peter,

Thank you so much for your help! This is working perfectly.
Fred's
 

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