Printing reports

  • Thread starter Thread starter dhoover
  • Start date Start date
D

dhoover

I have a button on a form that prints a group of reports. I need to be able
to tell it that if the report has no data, skip it and move to the next
report. The problem is that each report has a date at the top and access is
assuming that qualifies as data, and print empty pages with a data at the top.
Is there a way around this?
 
Could you post the SQL statement your button is using to print the "group of
reports"? How you are doing this now could offer approaches to what you
want to change.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Try adding the following code to the OnFormat parameter of the Detail section
of each report:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

On Error GoTo Detail_Format_Error

' Choose a color based on the shadeNextRow value
If shadeNextRow = True Then
Me.Section(acDetail).BackColor = shadedColor
Else
Me.Section(acDetail).BackColor = normalColor
End If

' Switch the color for the next row
shadeNextRow = Not shadeNextRow

Detail_Format_Exit:
Exit Sub

Detail_Format_Error:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Detail_Format_Exit

End Sub
 
This is the code



Private Sub cmdAdvPrint_Click()
On Error GoTo Err_cmdAdvPrint_Click

Dim stDocName As String

'Advance Credit Tickets
stDocName = "Deposit Advance Ticket"
DoCmd.OpenReport stDocName, acNormal

'Advance Debit Tickets
stDocName = "General Ledger Debit Advance Ticket"
DoCmd.OpenReport stDocName, acNormal

stDocName = "Business Loan Debit Advance Ticket"
DoCmd.OpenReport stDocName, acViewNormal


Exit_cmdAdvPrint_Click:
Exit Sub

Err_cmdAdvPrint_Click:
MsgBox Err.Description
Resume Exit_cmdAdvPrint_Click

End Sub

Jeff said:
Could you post the SQL statement your button is using to print the "group of
reports"? How you are doing this now could offer approaches to what you
want to change.

Regards

Jeff Boyce
Microsoft Office/Access MVP
I have a button on a form that prints a group of reports. I need to be
able
[quoted text clipped - 4 lines]
top.
Is there a way around this?
 
Depending on the version of Access you are using, your reports should have a
NoData event. You could add code in each report's NoData event that
canceled/closed the report.

You'd need to add error-handling code to your <command button> to intercept
the "this report was closed" error message (?2501 = err.number?) and resume
processing at the next report in the command button's code..

Good luck!

Jeff Boyce
Microsoft Office/Access

dhoover said:
This is the code



Private Sub cmdAdvPrint_Click()
On Error GoTo Err_cmdAdvPrint_Click

Dim stDocName As String

'Advance Credit Tickets
stDocName = "Deposit Advance Ticket"
DoCmd.OpenReport stDocName, acNormal

'Advance Debit Tickets
stDocName = "General Ledger Debit Advance Ticket"
DoCmd.OpenReport stDocName, acNormal

stDocName = "Business Loan Debit Advance Ticket"
DoCmd.OpenReport stDocName, acViewNormal


Exit_cmdAdvPrint_Click:
Exit Sub

Err_cmdAdvPrint_Click:
MsgBox Err.Description
Resume Exit_cmdAdvPrint_Click

End Sub

Jeff said:
Could you post the SQL statement your button is using to print the "group
of
reports"? How you are doing this now could offer approaches to what you
want to change.

Regards

Jeff Boyce
Microsoft Office/Access MVP
I have a button on a form that prints a group of reports. I need to be
able
[quoted text clipped - 4 lines]
top.
Is there a way around this?
 
Sorry about that...I gave you the wrong code and only half of the coded
needed to do something entirely different.

Try this instead.

Place this code in the "On No Data" Event:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to report", vbExclamation, "No Records"
Cancel = True
End Sub

I take it you are using a macro to batch your reports. If so, the print
jobs will go to the printer and any reports that do not have data will not
print. Instead a pop-up window will appear stating, "There are no records to
report", for each report that doesn't contain data. Once you click "Ok" the
next report will be evaluated. Only reports with data will print.
 
Back
Top