IF Statement Help

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have the below IF statements. How it is written, I would expect that if the
ITEM_TYPE = A and the PROD_FAM = STMP the IF vResponse2 would not be asked?
However I am finding that irregardless of the first IF result the MsgBox is
poping up with the question. Any ideas?

If (Me.ITEM_TYPE = "F") And (Me.PROD_FAM = "STMP") Then
Me.AR_CODE = "103"
Me.AP_CODE = "1220"
If vResponse2 = vbYes Then
Me.MATRIX_CODE = "5"
Else
Me.MATRIX_CODE = "3"
End If

End If
 
D

Dirk Goldgar

mattc66 via AccessMonster.com said:
I have the below IF statements. How it is written, I would expect that if
the
ITEM_TYPE = A and the PROD_FAM = STMP the IF vResponse2 would not be
asked?
However I am finding that irregardless of the first IF result the MsgBox
is
poping up with the question. Any ideas?

If (Me.ITEM_TYPE = "F") And (Me.PROD_FAM = "STMP") Then
Me.AR_CODE = "103"
Me.AP_CODE = "1220"
If vResponse2 = vbYes Then
Me.MATRIX_CODE = "5"
Else
Me.MATRIX_CODE = "3"
End If

End If


Why would you expect that? If the first If statement is true (ITEM_TYPE =
"F" and PROD_FAM = "STMP"), then the statements that follow, up to the
matching End If statement, will all be executed. That includes the "If
vResponse2 = vbYes" statement. There is nothing that would prevent that
statement from being executed; the code says to execute it.
 
M

mattc66 via AccessMonster.com

What I said was "ITEM_TYPE = A " not "F" it should go to the End If and not
fire correct? I think I have resolved it.

Dirk said:
I have the below IF statements. How it is written, I would expect that if
the
[quoted text clipped - 14 lines]

Why would you expect that? If the first If statement is true (ITEM_TYPE =
"F" and PROD_FAM = "STMP"), then the statements that follow, up to the
matching End If statement, will all be executed. That includes the "If
vResponse2 = vbYes" statement. There is nothing that would prevent that
statement from being executed; the code says to execute it.
 
D

Dirk Goldgar

mattc66 via AccessMonster.com said:
What I said was "ITEM_TYPE = A " not "F" it should go to the End If and
not
fire correct? I think I have resolved it.

Sorry, I missed that difference. You're quite right; the remaining
statements shouldn't fire. However, if you're talking about a MsgBox
appearing, nothing in that code is displaying a MsgBox. It's just looking
at what I guess is a variable that you would (presumably) have previously
set to the result of a call to the MsgBox function.

Anyway, I'm sorry for the unhelpful reply.
 
M

mattc66 via AccessMonster.com

That was my problem. I had the Message box at the top of the code. I moved it
into the IF statement and that resolved that issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top