Disable apostrophe/quotation mark key

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

Guest

I have a form that allows users to enter values into a table, which is then
the record source for a combo box elsewhere in the database. For
import/export purposes, I'd like to prevent users from entering anything with
an apostrophe, as that screws up the process. I just want the key disabled
for this form... I had the idea of assigning this code to the text box where
users enter the information:

Private Sub Charge_KeyPress(KeyAscii As Integer)
If KeyAscii = vb[Apostrophe?] Then
MsgBox "You may not use apostrophes in any fields"
End If
End Sub

For all I know, this might work if I can figure out what the apostrophe key
is called in VBA. Any thoughts? Is there some function in Access to do this
that I'm not aware of? TIA
 
tminn said:
I have a form that allows users to enter values into a table, which
is then the record source for a combo box elsewhere in the database.
For import/export purposes, I'd like to prevent users from entering
anything with an apostrophe, as that screws up the process. I just
want the key disabled for this form... I had the idea of assigning
this code to the text box where users enter the information:

Private Sub Charge_KeyPress(KeyAscii As Integer)
If KeyAscii = vb[Apostrophe?] Then
MsgBox "You may not use apostrophes in any fields"
End If
End Sub

For all I know, this might work if I can figure out what the
apostrophe key is called in VBA. Any thoughts? Is there some
function in Access to do this that I'm not aware of? TIA

You also have to set KeyAscii to zero to cancel the entry.

Private Sub Charge_KeyPress(KeyAscii As Integer)
If KeyAscii = 39 Then
MsgBox "You may not use apostrophes in any fields"
KeyAscii = 0
End If
End Sub

To find the ASCII value of a character just go to the immediate code window
and type...

?Asc(" ") <Enter>

....with the desired character between the quotes.
 
That worked great, thanks a lot, Rick!

Rick Brandt said:
tminn said:
I have a form that allows users to enter values into a table, which
is then the record source for a combo box elsewhere in the database.
For import/export purposes, I'd like to prevent users from entering
anything with an apostrophe, as that screws up the process. I just
want the key disabled for this form... I had the idea of assigning
this code to the text box where users enter the information:

Private Sub Charge_KeyPress(KeyAscii As Integer)
If KeyAscii = vb[Apostrophe?] Then
MsgBox "You may not use apostrophes in any fields"
End If
End Sub

For all I know, this might work if I can figure out what the
apostrophe key is called in VBA. Any thoughts? Is there some
function in Access to do this that I'm not aware of? TIA

You also have to set KeyAscii to zero to cancel the entry.

Private Sub Charge_KeyPress(KeyAscii As Integer)
If KeyAscii = 39 Then
MsgBox "You may not use apostrophes in any fields"
KeyAscii = 0
End If
End Sub

To find the ASCII value of a character just go to the immediate code window
and type...

?Asc(" ") <Enter>

....with the desired character between the quotes.
 
Back
Top