How to restrict certain characters in a text field?

O

Oisin

I want to restrict the entry of certain characters in a text field in Access
97. I know I can create a validation rule for the field but I don't see how
I can build an expression to disallow certain characters.
For example, I want to disallow commas and doubles quotes from the text
entered in a text field.

Your help is much appreciated,
Oisin.
 
A

Arvin Meyer

Using the BeforeUpdate event, which can cancel the update, you can write
something like (aircode):

Sub txtBoxName_BeforeUpdate(Cancel As Integer)
If Instr(Me.txtBoxName,",")>1 Then
MsgBox "Mama don't low no commas in here"
Cancel = True
End If
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Dirk Goldgar

Arvin Meyer said:
Using the BeforeUpdate event, which can cancel the update, you can
write something like (aircode):

Sub txtBoxName_BeforeUpdate(Cancel As Integer)
If Instr(Me.txtBoxName,",")>1 Then
MsgBox "Mama don't low no commas in here"
Cancel = True
End If
End Sub

It seems Mama 'lows one comma! :)
 
D

Dirk Goldgar

Lynn Trapp said:
Thus, you should have said:

Mama don't 'low no commas typed in here
Mama don't 'low no commas typed in here
We don't care what Mama don't 'low
Gonna type one comma any how
Mama just 'lowed one comma typed in here

LOL
 

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