Validation rule VBA format

A

ADixon

Hi all
I'm trying to write a procedure that will set the validation for a text box
on a form. The text box validation will be based on a value chosen by the
user from a combo box. For example: if the user selects 'PLU' in the combo,
then the procedure runs and the validation is set to 'Like "PLU????" Or IS
Null'. If they choose EAN8 then the validation is set for this selection. I
can't seem to get the format for the validation string correct. Here is a
snippet which throws up a compile error 'expected end of statement':

Dim strPLUValid As String

strPLUValid = "Like "PLU????" Or IS Null"

If Pack_Bcode_Type.Value = "PLU" Then
NewPack_Bcode.ValidationRule = strPLUValid
Else
End If

Any help is appreciated
 
M

Marshall Barton

ADixon said:
I'm trying to write a procedure that will set the validation for a text box
on a form. The text box validation will be based on a value chosen by the
user from a combo box. For example: if the user selects 'PLU' in the combo,
then the procedure runs and the validation is set to 'Like "PLU????" Or IS
Null'. If they choose EAN8 then the validation is set for this selection. I
can't seem to get the format for the validation string correct. Here is a
snippet which throws up a compile error 'expected end of statement':

Dim strPLUValid As String

strPLUValid = "Like "PLU????" Or IS Null"


That line is using embedded quotes incorrectly. Try using
this instead:

strPLUValid = "Like ""PLU????"" Or IS Null"

The rule is: To put a quote inside quotes, use two quotes.

OTOH, it is not clear that you really need to use the
validation rule instead of using code in the text box's
AfterUpdate event.
 
A

ADixon

Thanks Marshall

This works exactly as i needed.

For clarification, i only chose to use code instead of normal validation as
i needed to have multiple rules within if statements based on the choice made
within the combo box.

Thanks for the help
 

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

Similar Threads


Top