Disable apostrophe/quotation mark key

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
 
R

Rick Brandt

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

Guest

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.
 

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