Validating a quotation mark

  • Thread starter Thread starter Ashby
  • Start date Start date
A

Ashby

Try this code on the "ON KEY PRESS" event of the field.

If KeyAscii = 34 Then
MsgBox "Quotation marks are not allowed"
SendKeys "{BS}"
End If

The 34 represents the Ascii number for a quotation mark.

The sendkeys statement forces a backspace which removes
the quotation mark that was typed.
 
That worked beautifully, Ashby. Thanks!!
-----Original Message-----
Try this code on the "ON KEY PRESS" event of the field.

If KeyAscii = 34 Then
MsgBox "Quotation marks are not allowed"
SendKeys "{BS}"
End If

The 34 represents the Ascii number for a quotation mark.

The sendkeys statement forces a backspace which removes
the quotation mark that was typed.

.
 
Ashby said:
Try this code on the "ON KEY PRESS" event of the field.

If KeyAscii = 34 Then
MsgBox "Quotation marks are not allowed"
SendKeys "{BS}"
End If

The 34 represents the Ascii number for a quotation mark.

The sendkeys statement forces a backspace which removes
the quotation mark that was typed.

Cleaner and simpler than SendKeys is to use the line

KeyAscii = 0

instead.
 
Back
Top