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

If statement help required, incorrect values retunred

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. Private Sub LW_AfterUpdate()
  2. Me.WD = (Me.QtyKG + Me.EW) - Me.LW
  3. Me.WR = Me.WD / Me.QtyKG
  4.  
  5. If Me.WR >= Me.CheckOne & Me.WR <= Me.CheckTwo Then
  6.     Me.WC = "Passed"
  7.     Else
  8.         Me.WC = "Limit Exceeded"
  9.  
  10. End If
  11.  
  12. End Sub
  13.  
  14. EW       = Empty Weight
  15. LW       = Loaded Weight
  16. WD       = Weight Difference
  17. QtyKG    = Quantity in Kg
  18. CheckOne = -0.007
  19. CheckTwo = 0.007
  20.  
  21. WR= Weight Ratio
Jun 10 '14 #1

✓ answered by twinnyfo

Dij0o,

First,

Please use the Code Tags when inserting code.

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

Expand|Select|Wrap|Line Numbers
  1.     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!

Share this Question
Share on Google+
2 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,483
Dij0o,

First,

Please use the Code Tags when inserting code.

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

Expand|Select|Wrap|Line Numbers
  1.     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!
Jun 10 '14 #2

NeoPa
Expert Mod 15k+
P: 31,769
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.
Jun 29 '14 #3

Post your reply

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