Validate user input (Remove Commas)

A

AmytDev

I have a text field on a form and I am trying to prevent users from entering
commas into the field and having that save to a table. Does anyone know how I
could do this?

If a user enters a comma, I wanted to run a check and display a message to
not use commas.

Any suggestions?

Amytdev
 
D

Damian S

Hi AmytDev,

Put the following code into the keypress event of the control you don't want
comma's in...

If KeyAscii = Asc(",") Then
KeyAscii = 0
End If

You could put a msgbox to alert them that comma's aren't allowed if you like.

Enjoy!

Damian.
 
G

Graham Mandeno

Hi Amytdev

You could use the KeyPress event of your text box:

Private Sub YourTextBox_KeyPress(KeyAscii as Integer)
If KeyAscii = Asc(",") Then
KeyAscii = 0
MsgBox "Please do not use commas in this field"
End If
End Sub
 
A

AmytDev

That worked perfectly! Thank you both for your help!

Graham Mandeno said:
Hi Amytdev

You could use the KeyPress event of your text box:

Private Sub YourTextBox_KeyPress(KeyAscii as Integer)
If KeyAscii = Asc(",") Then
KeyAscii = 0
MsgBox "Please do not use commas in this field"
End If
End Sub

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

AmytDev said:
I have a text field on a form and I am trying to prevent users from
entering
commas into the field and having that save to a table. Does anyone know
how I
could do this?

If a user enters a comma, I wanted to run a check and display a message to
not use commas.

Any suggestions?

Amytdev
 
Top