By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

validation rule problem?

100+
P: 283
Hello all,

Im having some problems creating a validation rule with VBA. What I have is a form with a text box. When you start to type in the text box I want to have a validation rule set so you can only type certain numbers.

The problem I am having is with this code. It works fine but for some reason I can not contiune on with more ValideRule settings except for the first line. I cant figure out what is wrong with my syntax to get it to read the next line as still part of the first line.

I have tried using (,_) (& _) (" _) and many more variations so it will read the second and third lines but no luck.

Any help would be great!



Expand|Select|Wrap|Line Numbers
  1. Dim strValidRule as String
  2. Dim strValidText as String
  3.  
  4. strValidRule = "Between 1 And 10" Or "Between 20 And 30" _
  5.      Or "Between 40 And 50" Or "Between 60 And 70" _
  6.      Or "Between 80 And 90" Or "Between 100 And 110"
  7.  
  8.     strValidText = "Invalid Number."
  9.  
  10. Text7.ValidationRule = strValidRule
  11. Text7.ValidationText = strValidText
  12.  
  13.  
Nov 3 '10 #1

✓ answered by Mariostg

Try this:
Expand|Select|Wrap|Line Numbers
  1. strValidRule = "'Between 1 And 10' Or 'Between 20 And 30'" & _
  2.      " Or 'Between 40 And 50' Or 'Between 60 And 70'" & _
  3.      " Or 'Between 80 And 90' Or 'Between 100 And 110'"
  4.  

Share this Question
Share on Google+
2 Replies


100+
P: 332
Try this:
Expand|Select|Wrap|Line Numbers
  1. strValidRule = "'Between 1 And 10' Or 'Between 20 And 30'" & _
  2.      " Or 'Between 40 And 50' Or 'Between 60 And 70'" & _
  3.      " Or 'Between 80 And 90' Or 'Between 100 And 110'"
  4.  
Nov 4 '10 #2

100+
P: 283
Hi Mariostg,

Thanks a lot for the reply. I took your example and found that I just had to make one small adjustment and now it works great.

Really apprecitea your help! :D

adjusted code below
Expand|Select|Wrap|Line Numbers
  1. strValidRule = "Between 1 And 10 Or Between 20 And 30" & _ 
  2.      " Or Between 40 And 50 Or Between 60 And 70" & _ 
  3.      " Or Between 80 And 90 Or Between 100 And 110"
  4.  
Nov 6 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.