I need two different MsgBox(es) under the same command for work - help!

  • Thread starter Thread starter Doolittle
  • Start date Start date
D

Doolittle

Private Sub StoppedPayment_BeforeUpdate(Cancel As Integer)
Hi,
I'm new to groups!Thankyou for any posts people put up for me!Can
someone please explain why the first MsgBox appears yet the second
doesn't? Thanks,
Doolittle



If StoppedPayment = True Then
If MsgBox("Confirm you want to STOP PAYMENT", vbYesNo +
vbDefaultButton2 + vbCritical) = vbNo Then
Cancel = True
StoppedPayment.Undo
Exit Sub

Else

If Payment_Amount = "£0.00" Then
If MsgBox("Previous payment not made", vbOKCancel) = vbCancel
Then
Cancel = True
StoppedPayment.Undo
Exit Sub
End If
End If
End If
End If
End Sub
 
There are 2 reasons why you only get the one message box.

1. The value of StoppedPayment is checked when the If statement begins and
it can have only one value. If the value is "True" then you will get the
first message box. If the value is "False" then you will get the second
message box. That's the way your logic is laid out. It looks like you
thought that perhaps the statement StoppedPayment.Undo would change the
value of StoppedPayment to "False" and therefore run the Else part of the If
statement. When an If statement runs it will only run the If or the
Else...not both.

2. The second reason is that you have told it to Exit Sub immediately after
the StoppedPayment.Undo, so, even if you didn't have the Else statement it
still would nver get to the second one.
 
Back
Top