Missing End If in Code ?? Where?

D

Dave Elliott

If vbYes = MsgBox("Do you want to print the customer's receipt?", vbQuestion
+ _
vbYesNo, "Print Receipt?") Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
If (IsNull(Payment) = False) And (Balance) = 0 Then
DoCmd.OpenReport "InvoiceReport", acNormal, "",
"[TimeID]=[Forms]![TimeCards]![TimeID]"
If [Forms]![TimeCards]![BidDiscAmt] < DSum("Payment", "TPaymentSub",
"TimeID = [Forms]![TimeCards]!TimeID") Then
Reports!InvoiceReport!QuoteInvLabel.Caption = "Credit Invoice"
Else: Reports!InvoiceReport!QuoteInvLabel.Caption = "Invoice"
End If
 
M

Mike Painter

Dave said:
If vbYes = MsgBox("Do you want to print the customer's receipt?",
vbQuestion + _
vbYesNo, "Print Receipt?") Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
If (IsNull(Payment) = False) And (Balance) = 0 Then
DoCmd.OpenReport "InvoiceReport", acNormal, "",
"[TimeID]=[Forms]![TimeCards]![TimeID]"
If [Forms]![TimeCards]![BidDiscAmt] < DSum("Payment",
"TPaymentSub", "TimeID = [Forms]![TimeCards]!TimeID") Then
Reports!InvoiceReport!QuoteInvLabel.Caption = "Credit
Invoice" Else: Reports!InvoiceReport!QuoteInvLabel.Caption =
"Invoice" End If

You have three If statements and only one end if.
If an IF is not limited to one line then it must have an End If.
I never use one line IF statements to avoid the confusion.

I don't know if they re nested or not.
 
A

Allan Murphy

Dave

When I do coding using If ..then... else... end if I always after entering
the IF .... then my next line is END IF regardless of the number of lines
for the action
that way I do not confused when doing nested if statements.

I would have written the code as follows

If vbYes = MsgBox("Do you want to print the customer's receipt?", vbQuestion
+ vbYesNo, "Print Receipt?") Then

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

If (IsNull(Payment) = False) And (Balance) = 0 Then
DoCmd.OpenReport "InvoiceReport", acNormal, "",
"[TimeID]=[Forms]![TimeCards]![TimeID]"
End if

If [Forms]![TimeCards]![BidDiscAmt] < DSum("Payment", "TPaymentSub",
"TimeID = [Forms]![TimeCards]!TimeID") Then
Reports!InvoiceReport!QuoteInvLabel.Caption = "Credit Invoice"
Else
Reports!InvoiceReport!QuoteInvLabel.Caption = "Invoice"
End if

End if

Allan Murphy
Email: (e-mail address removed)
 
R

RuralGuy

If vbYes = MsgBox("Do you want to print the customer's receipt?",
vbQuestion + vbYesNo, "Print Receipt?") Then

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
If (IsNull(Payment) = False) And (Balance) = 0 Then
DoCmd.OpenReport "InvoiceReport", acNormal, "",
"[TimeID]=[Forms]![TimeCards]![TimeID]"
If [Forms]![TimeCards]![BidDiscAmt] < DSum("Payment","TPaymentSub",
"TimeID = [Forms]![TimeCards]!TimeID") Then
Reports!InvoiceReport!QuoteInvLabel.Caption = "Credit Invoice"

[THERE SHOULD NOT BE A COLON AFTER THE NEXT ELSE!]
Else:
Reports!InvoiceReport!QuoteInvLabel.Caption = "Invoice"
End If
END IF
END IF

Dave,

Mike and Allan got it. I too see two missing END IF statements
plus an extra ":".

Sometimes just indenting makes the answer clear.

HTH

RuralGuy
 
V

Van T. Dinh

The colon is being used as the statement separator so it should be OK.
Admittedly, I always put Else on its own line rather than using the
statement separator.
 
R

RuralGuy

Van T. Dinh said:
The colon is being used as the statement separator so it should be OK.
Admittedly, I always put Else on its own line rather than using the
statement separator.

Thanks Van. Are you saying as written by OP it would still
function as the "Else" clause for the "If"? I'm not familiar with
that syntax.

I am familiar with putting two statements on the same line separated
by a colon, but they both execute and that's not what is desired here.

RuralGuy
 
V

Van T. Dinh

Yes. The use of the colon is equivalent to putting the next statement on
the next line, i.e. it is exactly the same as Cr + Lf.

I don't think that the 2 statements separated by colon are executed
concurrently. When you step through the code, the yellow highlighter
wrongly high-light the whole line but if you step one statement at a time
(F8), you will find that you have to hit F8 twice to get to the next line
after the 2 statements separated by colon.

--
HTH
Van T. Dinh
MVP (Access)
 
R

RuralGuy

Van T. Dinh said:
Yes. The use of the colon is equivalent to putting the next statement on
the next line, i.e. it is exactly the same as Cr + Lf.

I don't think that the 2 statements separated by colon are executed
concurrently. When you step through the code, the yellow highlighter
wrongly high-light the whole line but if you step one statement at a time
(F8), you will find that you have to hit F8 twice to get to the next line
after the 2 statements separated by colon.

Thanks Van. There is always something to learn on these news groups. I
appreciate you taking the time to explain further. I didn't mean to imply
that the two statements executed together, sorry. I was aware they were
executed sequentially.

And a happy Sunday morning to you!

RuralGuy
 

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