Showing posts with label Reports. Show all posts
Showing posts with label Reports. Show all posts

6/15/10

Do not print a Report if there is no data

If you want to stop the printing of a report that has no data, then there are two steps that you need to do. Firstly, you need to use the Report's NoData event to stop it being printed:

Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub

The problem with using the NoData event programmatically is that it raises an error in the calling code. Therefore, you will also need to add an error handle to the procedure that opens the Report specifically to trap this error:

Private Sub cmdPrint_Click()
On Error GoTo E_Handle
DoCmd.OpenReport "rptName"
sExit:
Exit Sub
E_Handle:
Select Case Err.Number
Case 2501
Case Else
MsgBox Err.Description, vbCritical + vbOKOnly, "Error: " & Err.Number
End Select
Resume sExit
End Sub


http://www.applecore99.com/rpt/rpt010.asp

Previewing a report

If you want to preview a report, Access will normally open it up full-size, so that you can't see the whole page at once. If you wish to have your reports opened as large as the screen will allow, then when you open the report add a line of code:

DoCmd.OpenReport "rptName",acViewPreview
DoCmd.RunCommand acCmdFitToWindow

http://www.applecore99.com/rpt/rpt008.asp

Printing the name of the Report and/or the name of the database on a Report

Sometimes you may want to print a report that has information such as the name of the Report, or the name of the Database, in the Report's footer, to identify the print out. To do this, you need to add a Textbox to the relevant location on the Report, and then set the ControlSource to:

=[Name]

For the name of the Database, you would instead set the ControlSource to:

=Dir([CurrentDb].[Name],16)

Note that we cannot use the VBA constant vbDirectory, and so must instead use the numeric value, which is 16.

http://www.applecore99.com/rpt/rpt018.asp