On No Data Cancels 2nd report

D

dbl

Hi I have 2 reports that I bring up using the following code:

Dim stDocName As String

stDocName = "LateEstimates"
DoCmd.OpenReport stDocName, acPreview

stDocName = "LateInvoices"
DoCmd.OpenReport stDocName, acPreview

I use the following code in the On No Data events procedure for each report
MsgBox "No Estimates Outstanding"
Cancel = True

All works well if there is data, but when the first report hasn't any data
to view
I get the message box as you would expect, when I click OK I get the following

Error message "Event Cancelled" and no second report.

How do I get the code to continue so that the second report is requested?

Bob
 
F

fredg

Hi I have 2 reports that I bring up using the following code:

Dim stDocName As String

stDocName = "LateEstimates"
DoCmd.OpenReport stDocName, acPreview

stDocName = "LateInvoices"
DoCmd.OpenReport stDocName, acPreview

I use the following code in the On No Data events procedure for each report
MsgBox "No Estimates Outstanding"
Cancel = True

All works well if there is data, but when the first report hasn't any data
to view
I get the message box as you would expect, when I click OK I get the following

Error message "Event Cancelled" and no second report.

How do I get the code to continue so that the second report is requested?

Bob

Try the code this way.

On Error GoTo Err_Handler
Dim stDocName As String

FirstReport:
strDocName = "rptNumberOne"
DoCmd.OpenReport stDocName, acViewPreview

SecondReport:
strDocName = "rptNumberTwo"
DoCmd.OpenReport stDocName, acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
If stDocName = "rptNumberOne" Then
Resume SecondReport
ElseIf stDocName = "rptNumberTwo" Then
Resume Exit_Sub
End If
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_Sub
End If
 
D

dbl

Hello fredg,

I have entered the code as below:

Private Sub Command240_Click()
On Error GoTo Err_Handler

Dim stDocName As String

FirstReport:
stDocName = "Late Estimates By Bodyshops"
DoCmd.OpenReport stDocName, acViewPreview

SecondReport:
stDocName = "late Invoices By Bodyshops"
DoCmd.OpenReport stDocName, acViewPreview
Exit Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
If stDocName = "Late Estimates" Then
Resume SecondReport
ElseIf stDocName = "late Invoices By Bodyshops" Then
Resume Exit_Sub
End If
Else
MsgBox "Error#:" & Err.Number & Err.Description
Resume Exit_Sub
End If

End Sub

The problem I how have is I get a "Complie Error Label not defined" on the
Resume Exit_Sub line

Can you see where am I doing wrong?

Thanks for your help

Bob
 
F

fredg

Hello fredg,

I have entered the code as below:

Private Sub Command240_Click()
On Error GoTo Err_Handler

Dim stDocName As String

FirstReport:
stDocName = "Late Estimates By Bodyshops"
DoCmd.OpenReport stDocName, acViewPreview

SecondReport:
stDocName = "late Invoices By Bodyshops"
DoCmd.OpenReport stDocName, acViewPreview
Exit Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
If stDocName = "Late Estimates" Then
Resume SecondReport
ElseIf stDocName = "late Invoices By Bodyshops" Then
Resume Exit_Sub
End If
Else
MsgBox "Error#:" & Err.Number & Err.Description
Resume Exit_Sub
End If

End Sub

The problem I how have is I get a "Complie Error Label not defined" on the
Resume Exit_Sub line

Can you see where am I doing wrong?

Thanks for your help

Bob

Look again at what I sent you.
You didn't copy what I wrote .
You left off the underscore on the first Exit_Sub. :-(

DoCmd.OpenReport etc....
Exit_Sub:
Exit Sub
Err_Handler:
etc.
 
D

dbl

Fredg

I have changed that, but it still will not open the second report if there
is no data in the first. I have rechecked all the code and I can not see
any more input errors.

Bob
 

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