IF Less Than (<) not working in VB Code - Access 2000

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ryan.paquette@gmail.com

    IF Less Than (<) not working in VB Code - Access 2000

    Hello'

    I am attempting to provide validation for a field on a form through a
    command.
    (the validation is only part of the command). The field is a text box
    formatted as a fixed number...

    Basically I want the resulting value to only be allowed to be between
    2 & 8.

    The code works fine for the greater than (>) but for some reason does
    not work for less than(<) ??
    abbreviated code snippet:

    If Me.Field "2" And Me.Field < "8" Then
    Me.cmdSave.Visi ble = True
    MsgBox ("Good")
    Else
    MsgBox ("Bad")
    If Me.cmdSave.Visi ble = True Then
    Me.cmdSave.Visi ble = False
    End If
    End If

    I even went as far as to leave out the AND portion of the statement &
    only put in the 1 criteria (less than 8) & vice versa. Also used the
    (.Value) qualifier for the field.

    The greater than 2 criteria works everytime (whether after the less
    than AND) portion of the line or before it, or on it's own with no AND
    statement.

    But the less than # will NOT work???

    Any ideas why?
  • Salad

    #2
    Re: IF Less Than (&lt;) not working in VB Code - Access 2000

    ryan.paquette@g mail.com wrote:
    Hello'
    >
    I am attempting to provide validation for a field on a form through a
    command.
    (the validation is only part of the command). The field is a text box
    formatted as a fixed number...
    >
    Basically I want the resulting value to only be allowed to be between
    2 & 8.
    >
    The code works fine for the greater than (>) but for some reason does
    not work for less than(<) ??
    abbreviated code snippet:
    >
    If Me.Field "2" And Me.Field < "8" Then
    Me.cmdSave.Visi ble = True
    MsgBox ("Good")
    Else
    MsgBox ("Bad")
    If Me.cmdSave.Visi ble = True Then
    Me.cmdSave.Visi ble = False
    End If
    End If
    >
    I even went as far as to leave out the AND portion of the statement &
    only put in the 1 criteria (less than 8) & vice versa. Also used the
    (.Value) qualifier for the field.
    >
    The greater than 2 criteria works everytime (whether after the less
    than AND) portion of the line or before it, or on it's own with no AND
    statement.
    >
    But the less than # will NOT work???
    >
    Any ideas why?
    Hmmm...do you only permit numbers from 3 to 7? If not, maybe use >= and <=.

    Comment

    • ryan.paquette@gmail.com

      #3
      Re: IF Less Than (&lt;) not working in VB Code - Access 2000

      Hmmm...do you only permit numbers from 3 to 7?  If not, maybe use >= and <=.
      With or without the (=)'s I still get the same issue.

      If the field ends up being less than (<) the lower value then the code
      works fine...i.e Error message.
      If the field ends up being greater (>) the higher value then the code
      does not work... i.e. NO error message.

      It's like Access is ignoring the greater than symbol???





      Comment

      • ryan.paquette@gmail.com

        #4
        Re: IF Less Than (&lt;) not working in VB Code - Access 2000

        sry... the Less than < symbol is being ignored by access...

        Comment

        • paii, Ron

          #5
          Re: IF Less Than (&lt;) not working in VB Code - Access 2000


          "ryan.paquette@ gmail.com" <Ryan.Paquette@ gmail.comwrote in message
          news:d482ceaa-8d08-49b1-b5f5-34c58db190ed@i7 6g2000hsf.googl egroups.com...
          Hello'
          >
          I am attempting to provide validation for a field on a form through a
          command.
          (the validation is only part of the command). The field is a text box
          formatted as a fixed number...
          >
          Basically I want the resulting value to only be allowed to be between
          2 & 8.
          >
          The code works fine for the greater than (>) but for some reason does
          not work for less than(<) ??
          abbreviated code snippet:
          >
          If Me.Field "2" And Me.Field < "8" Then
          Me.cmdSave.Visi ble = True
          MsgBox ("Good")
          Else
          MsgBox ("Bad")
          If Me.cmdSave.Visi ble = True Then
          Me.cmdSave.Visi ble = False
          End If
          End If
          >
          I even went as far as to leave out the AND portion of the statement &
          only put in the 1 criteria (less than 8) & vice versa. Also used the
          (.Value) qualifier for the field.
          >
          The greater than 2 criteria works everytime (whether after the less
          than AND) portion of the line or before it, or on it's own with no AND
          statement.
          >
          But the less than # will NOT work???
          >
          Any ideas why?
          Can the value of Me.Field be greater then 9? A text compare of "10" < "8"
          is true.

          Try If cint(Me![Field]) 2 And cint(Me![Field]) < 8 Then



          Comment

          • ryan.paquette@gmail.com

            #6
            Re: IF Less Than (&lt;) not working in VB Code - Access 2000

            On Oct 3, 2:32 pm, "paii, Ron" <n...@no.comwro te:
            "ryan.paque...@ gmail.com" <Ryan.Paque...@ gmail.comwrote in message
            >
            news:d482ceaa-8d08-49b1-b5f5-34c58db190ed@i7 6g2000hsf.googl egroups.com...
            >
            >
            >
            >
            >
            Hello'
            >
            I am attempting to provide validation for a field on a form through a
            command.
            (the validation is only part of the command). The field is a text box
            formatted as a fixed number...
            >
            Basically I want the resulting value to only be allowed to be between
            2 & 8.
            >
            The code works fine for the greater than (>) but for some reason does
            not work for less than(<) ??
            abbreviated code snippet:
            >
                If Me.Field "2" And Me.Field < "8" Then
                       Me.cmdSave.Visi ble = True
                       MsgBox ("Good")
                  Else
                      MsgBox ("Bad")
                            If Me.cmdSave.Visi ble = True Then
                                Me.cmdSave.Visi ble = False
                            End If
                End If
            >
            I even went as far as to leave out the AND portion of the statement &
            only put in the 1 criteria (less than 8) & vice versa. Also used the
            (.Value) qualifier for the field.
            >
            The greater than 2 criteria works everytime (whether after the less
            than AND) portion of the line or before it, or on it's own with no AND
            statement.
            >
            But the less than # will NOT work???
            >
            Any ideas why?
            >
            Can the value of Me.Field be greater then 9? A text compare of  "10" < "8"
            is true.
            >
            Try   If cint(Me![Field]) 2 And cint(Me![Field]) < 8 Then- Hide quoted text -
            >
            - Show quoted text -
            You are the Man Ron!!!
            That works!
            So when an integer is in text field & I want to validate it based on
            the Integer value, then I need to use the Cint function.
            I got it committed to memory now! thank goodness for google groups...

            Comment

            • Albert D. Kallal

              #7
              Re: IF Less Than (&lt;) not working in VB Code - Access 2000

              "ryan.paquette@ gmail.com" <Ryan.Paquette@ gmail.comwrote in message
              news:b0d7ffd6-48f5-4d80-9c30-9ad16299d6ea@t5 4g2000hsg.googl egroups.com...
              On Oct 3, 2:32 pm, "paii, Ron" <n...@no.comwro te:
              "ryan.paque...@ gmail.com" <Ryan.Paque...@ gmail.comwrote in message
              >
              news:d482ceaa-8d08-49b1-b5f5-34c58db190ed@i7 6g2000hsf.googl egroups.com...
              >So when an integer is in text field & I want to validate it based on
              the Integer value, then I need to use the Cint function.
              I got it committed to memory now! thank goodness for google groups...

              No, you don't have to. Your problem is:


              If Me.Field "2" And Me.Field < "8" Then

              You are using strings for "2", you should use

              If Me.Field 2 And Me.Field < 8 Then


              --
              Albert D. Kallal (Access MVP)
              Edmonton, Alberta Canada
              pleaseNOOSpamKa llal@msn.com




              Comment

              Working...