Results 1 to 8 of 8
  1. #1
    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. #2
    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. #3
    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
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Quote Originally Posted by StarTrekker View Post
    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.
    Paul

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

    Else became ElseIf.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Quote Originally Posted by StarTrekker View Post
    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.
    Paul

  7. #7
    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
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    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.
    Paul

Posting Permissions

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