validation rule problem?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slenish
    Contributor
    • Feb 2010
    • 283

    #1

    validation rule problem?

    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!



    Code:
    Dim strValidRule as String
    Dim strValidText as String
    
    strValidRule = "Between 1 And 10" Or "Between 20 And 30" _
         Or "Between 40 And 50" Or "Between 60 And 70" _
         Or "Between 80 And 90" Or "Between 100 And 110"
    
        strValidText = "Invalid Number."
    
    Text7.ValidationRule = strValidRule
    Text7.ValidationText = strValidText
  • Mariostg
    Contributor
    • Sep 2010
    • 332

    #2
    Try this:
    Code:
    strValidRule = "'Between 1 And 10' Or 'Between 20 And 30'" & _
         " Or 'Between 40 And 50' Or 'Between 60 And 70'" & _
         " Or 'Between 80 And 90' Or 'Between 100 And 110'"

    Comment

    • slenish
      Contributor
      • Feb 2010
      • 283

      #3
      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
      Code:
      strValidRule = "Between 1 And 10 Or Between 20 And 30" & _ 
           " Or Between 40 And 50 Or Between 60 And 70" & _ 
           " Or Between 80 And 90 Or Between 100 And 110"

      Comment

      Working...