Validation rule in access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ckpoll2
    New Member
    • Sep 2006
    • 76

    Validation rule in access

    Hello,

    I have a validation rule in a text box on a form. The rule is that if Combo12 starts with "Credit Hours -*" than only allow numbers less than or equal to 2 in there. Any number of words could come after credit hours, hence the wildcard character. The formula that I'm using is:

    [Hours]<=2 Or [Combo12]<>"Credit Hours -*"

    but it isn't working. What am I doing wrong?

    Thanks,

    Charlie
  • racquetballguy
    New Member
    • Aug 2006
    • 20

    #2
    How about something like

    Val(Mid(thestri ng,start position of #,Lenght of #))

    If you need to get total length of string for Length of #, you can use Len

    Ivan

    Comment

    • ckpoll2
      New Member
      • Sep 2006
      • 76

      #3
      That didn't seem to work. Do you know of any variation of the formula that I listed in my earlier thread? I'm thinking it has something to do with using "like", but I'm not really sure.

      Thanks for your help

      Comment

      • racquetballguy
        New Member
        • Aug 2006
        • 20

        #4
        Are you comparing what is entered to 2 seperate parameters "hours" and "combo 12"? Does your user have to enter the text "credit hours - "?

        If all they are really entering is a number, just compare it locally for that specific number.

        If this is coming from a table that has the text "credit hours - " already there you are better off using a query.

        Ivan

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by ckpoll2
          Hello,

          I have a validation rule in a text box on a form. The rule is that if Combo12 starts with "Credit Hours -*" than only allow numbers less than or equal to 2 in there. Any number of words could come after credit hours, hence the wildcard character. The formula that I'm using is:

          [Hours]<=2 Or [Combo12]<>"Credit Hours -*"

          but it isn't working. What am I doing wrong?

          Thanks,

          Charlie
          'Assuming the Text Box is called txtTest, try this in the BeforeUpdate()
          'Event of this Text Box to enforce Validation
          Code:
          Private Sub txtTest_BeforeUpdate(Cancel As Integer)
          If Me![Combo12].Value Like "Credit Hours -*" Then
            If Me![txtTest].Value <= 2 Then
            Else
              MsgBox "Value must be <= 2"
              Cancel = True
            End If
          End If
          End Sub

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32639

            #6
            Originally posted by ckpoll2
            Hello,

            I have a validation rule in a text box on a form. The rule is that if Combo12 starts with "Credit Hours -*" than only allow numbers less than or equal to 2 in there. Any number of words could come after credit hours, hence the wildcard character. The formula that I'm using is:

            [Hours]<=2 Or [Combo12]<>"Credit Hours -*"

            but it isn't working. What am I doing wrong?

            Thanks,

            Charlie
            Try something like
            Code:
            [Hours]<=2 Or [Combo12] Not Like "Credit Hours -*"

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Logically, I don't think this rule will work.

              You are saying that the the rule is that the hours have to be less than 2 or the Combo12 not like "Credit Hours -*". I don't think you can do this kind of logic with a validation rule and would suggest you look at Adezii's solution.

              Mary

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32639

                #8
                You're right Mary.
                Rather than VBA code (which would work) you could try :
                Code:
                <=IIf([Combo12] Like "Credit Hours -*",2,99999)

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Originally posted by NeoPa
                  You're right Mary.
                  Of course I'm right, I'm always right. :D

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32639

                    #10
                    Originally posted by mmccarthy
                    Of course I'm right, I'm always right. :D
                    Come now Mary, you should be able to remember more than half of your posts :wicked grin:

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Originally posted by NeoPa
                      Come now Mary, you should be able to remember more than half of your posts :wicked grin:
                      Half, HALF !!!!!!!!

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32639

                        #12
                        Originally posted by mmccarthy
                        Originally posted by NeoPa
                        Come now Mary, you should be able to remember more than half of your posts :wicked grin:
                        Half, HALF !!!!!!!!
                        Maybe that was a little churlish - Five eighths maybe.

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          Originally posted by NeoPa
                          Maybe that was a little churlish - Five eighths maybe.
                          I refuse to disintegrate this argument into it's normal childish level. I am above such juvenile behaviour.

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32639

                            #14
                            Originally posted by mmccarthy
                            I refuse to disintegrate this argument into it's normal childish level. I am above such juvenile behaviour.
                            Lol Yeah, and what about the Leprechauns? Are they real too?

                            Comment

                            • MMcCarthy
                              Recognized Expert MVP
                              • Aug 2006
                              • 14387

                              #15
                              Originally posted by NeoPa
                              Lol Yeah, and what about the Leprechauns? Are they real too?
                              Loathe as I am to repeat myself ....

                              GET LOST ADE :D

                              Comment

                              Working...