# Thread: Need some help with an IF statement

1. Registered User
Join Date
Feb 2009
Posts
5

## Unanswered: Need some help with an IF statement

I have written the statement below in hope that it would display warnings based on the criteria. I does display the warnings but only for the first instance. For example it will display a message for the IF statement and if the second IF statement is true it doers not display the message. I was excepting to get to message boxes when it meet both criteria.

I am fairly new to this and would appreciate any help you can provide. Thanks -Pat

I also tried to breaking them out into separate IF statements but that did not help either.

If intWantQty >= 1 And ysnCollecting.Value = True And intTQOH.Value > 0 Then
MsgBox "There appears to be discrepancies in the trade invenvtory vs. the want list." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to YES" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1" & Chr(13) & Chr(10) & "AND Trade Quantity is greater 0", vbOKOnly, "Warning - Trade vs. Want Discrepancy"
Else
If ysnCollecting.Value = False And intWantQty.Value >= 1 Then
MsgBox "There appears to be collecting discrepancies." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to No" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1", vbOKOnly, "Warning - Collecting Discrepancy"
End If
End If

2. Registered User
Join Date
May 2005
Posts
28
If the 1st is displayed than the result of your 1st IF is True, thus it will not move to the second If statement as it is a condition of the ELSE from the first IF.

If you want both IF test's to evaluate you should replace the ELSE with an END IF, and clear the last END IF.

3. L33t Helpa Munky
Join Date
Nov 2007
Location
Adelaide, South Australia
Posts
4,049
If intWantQty >= 1 And ysnCollecting.Value = True And intTQOH.Value > 0 Then
MsgBox "There appears to be discrepancies in the trade invenvtory vs. the want list." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to YES" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1" & Chr(13) & Chr(10) & "AND Trade Quantity is greater 0", vbOKOnly, "Warning - Trade vs. Want Discrepancy"
ElseIf
If ysnCollecting.Value = False And intWantQty.Value >= 1 Then
MsgBox "There appears to be collecting discrepancies." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to No" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1", vbOKOnly, "Warning - Collecting Discrepancy"
End If

4. Registered User
Join Date
May 2005
Location
Nevada, USA
Posts
2,888
Provided Answers: 6
Originally Posted by StarTrekker
If intWantQty >= 1 And ysnCollecting.Value = True And intTQOH.Value > 0 Then
MsgBox "There appears to be discrepancies in the trade invenvtory vs. the want list." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to YES" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1" & Chr(13) & Chr(10) & "AND Trade Quantity is greater 0", vbOKOnly, "Warning - Trade vs. Want Discrepancy"
ElseIf
If ysnCollecting.Value = False And intWantQty.Value >= 1 Then
MsgBox "There appears to be collecting discrepancies." & Chr(13) & Chr(10) & " Please carefully review and correct." & Chr(13) & Chr(10) & "TRIGGER" & Chr(13) & Chr(10) & "Collecting is set to No" & Chr(13) & Chr(10) & "AND Want Quantity is equal to or greater than 1", vbOKOnly, "Warning - Collecting Discrepancy"
End If
I'm fairly confident you want to edit this code.

5. L33t Helpa Munky
Join Date
Nov 2007
Location
Adelaide, South Australia
Posts
4,049
I did.

Else became ElseIf.

6. Registered User
Join Date
May 2005
Location
Nevada, USA
Posts
2,888
Provided Answers: 6
Originally Posted by StarTrekker
I did.

Else became ElseIf.
That will not achieve the stated goal of getting two message boxes if both conditions are met (presuming I'm reading right). AhrenL's recommendation of breaking the code into two distinct If/Then blocks was already correct.

7. L33t Helpa Munky
Join Date
Nov 2007
Location
Adelaide, South Australia
Posts
4,049
Oh. I didn't realise that was the case.

Mind you I'd never do that -- it would only serve to annoy the user imo

8. Registered User
Join Date
May 2005
Location
Nevada, USA
Posts
2,888
Provided Answers: 6
I certainly agree with you there. I'd build a string variable that contained one or the other or both warnings if applicable, then present one message box to the user.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•