Validate user input (Remove Commas)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

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

Back
Top