Creating an Empty Report

To create a new report, you use the CreateReport method. Here is the basic syntax.



as Access.Report



= CreateReport

Below is an example that creates a new empty report and deletes any existing report with the same name before creating the new report.

Sub CreateNewReport()

'set the name of the new report strReportName = "Customers"

'delete any existing report with that name For Each aoAccessObj In CurrentProject.AllReports If aoAccessObj.Name = strReportName Then

DoCmd.DeleteObject acReport, strReportName End If Next aoAccessObj

'create a new Customers Report Set rptCustomers = CreateReport

'save and close the new report DoCmd.Save , strReportName DoCmd.Close

End Sub

First, the code loops through the AllReports collection to delete any existing report with the same name. Then, the Access report object rptCustomers is assigned to the CreateReport method. The report is then saved with the name specified. At this point, the report is empty and contains no controls. Let's look at how to add controls to the report.

0 0

Post a comment