View Full Version : Disallowing input of " using validation rule


chunboon
11-12-2009, 04:54 AM
Hi! Im trying to disallow the input of " in my name field using the validation rule but i cant seem to get it. Does anyone know how this can be done?

Also what does it mean when i have *x*, what does the 2 * mean?

THanks in advance!

JANR
11-12-2009, 05:57 AM
Hi! Im trying to disallow the input of " in my name field using the validation rule but i cant seem to get it.

Put this in the validation rule:

Like <> Chr(34)

* is used as a wildcard to do searches in access.

JR

JANR
11-12-2009, 08:41 AM
If you want to give the user a more meaningfull warning, then you can move the validation from the table to your form instead and use some code.

You can use the control's BeforeUpdate event, it will look something like this:

Private Sub Text0_BeforeUpdate(Cancel As Integer)
If InStr(Me!Text0, Chr(34)) Then
MsgBox "Illegal use of quotemark"
Cancel = True
End If

End Sub

Replace text0 with the name of your own control.

A third way is to remove the illegal " from the field for the user by using the replace function. You can use the control's After_update event instead. Something like this:

Private Sub Text2_AfterUpdate()
Me!Text2 = Replace(Me!Text2, Chr(34), "", 1) ' Remove " from string
End Sub

JR

Galaxiom
11-12-2009, 01:54 PM
Like <> Chr(34)


This looked unlikely to me so I tried it.
The only thing I could enter was a Null

This is what I would use:

Not Like "*" & Chr(34) & "*"

chunboon
11-12-2009, 05:16 PM
works well! thanks for the help appreciate it! =D

JANR
11-12-2009, 10:38 PM
This looked unlikely to me so I tried it.
The only thing I could enter was a Null


Me too, what was I thinking about :o

works well! thanks for the help appreciate it! =D

Glad you got it to work.

JR