If statement help required, incorrect values retunred

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dij0o
    New Member
    • Jun 2014
    • 1

    If statement help required, incorrect values retunred

    I've written some VBA code on certain events, my first time so please be patient.

    basically after I enter LW value I want it to check if the value of WR is between the range of -0.007 to 0.007 but not matter the value the if statement returns "Passed" always.

    I've copied the code below could someone point out what I'm doing wrong

    Code:
    Private Sub LW_AfterUpdate()
    Me.WD = (Me.QtyKG + Me.EW) - Me.LW
    Me.WR = Me.WD / Me.QtyKG
    
    If Me.WR >= Me.CheckOne & Me.WR <= Me.CheckTwo Then
        Me.WC = "Passed"
        Else
            Me.WC = "Limit Exceeded"
               
    End If
    
    End Sub
    
    EW       = Empty Weight
    LW       = Loaded Weight
    WD       = Weight Difference
    QtyKG    = Quantity in Kg
    CheckOne = -0.007
    CheckTwo = 0.007
    
    WR= Weight Ratio
    Last edited by Rabbit; Jun 10 '14, 04:30 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    Dij0o,

    First,

    Please use the Code Tags when inserting code.

    Second, I think the error comes with your Conditional Statement:

    Code:
        If Me.WR >= Me.CheckOne And Me.WR <= Me.CheckTwo Then
    It appears you used an ampersand ("&") instead of teh Boolean Operator "And".

    This should do the trick.

    Please let me know if this hepps!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      You may find that Before Posting (VBA or SQL) Code has a number of helpful tips for you. If you go through these you'll find much fewer problems.

      Comment

      Working...