Using a Report |
|
Selecting a Report |
To perform an operation on a report, you may need to select it first. To do this, in the Reports section of the Database window, you can simply click it, once. To programmatically select a report, you can use the DoCmd object that is equipped with the SelectObject() method. The syntax to use would be: DoCmd.SelectObject acReport, [objectname][, indatabasewindow] The first argument must be acReport to indicate that the object you are selecting is a report. The second argument is the name of the report you want to select. To select but only highlight the report in the Database window, you can pass the third argument as True. |
If the report is already opened and it is displaying, and if you omit the third argument or pass it as False, the report would be displayed in the foreground. If the report is not opened and you omit the third argument or pass it as False, you would receive an error.
When you start Microsoft Access and open a database, if it has some reports, obviously they would be closed. To use a report, you can open it first. A report can be opened in Design View or in Print Preview. If you (or the user) double-click(s) a report in the Reports section of the Database window, it opens in Print Preview. This views allows the user to review the document before printing. By default, the view is blurred to show as much of its area as possible. To be able to read it, you (or the user) can click the body of the report to zoom. To print it, you can click the Print button on the toolbar to send the document to the printer. A report can also display in Design View. To show it, if the report is currently closed, you can right-click it and click Design View. You can also select it first, then click the Design button under the title bar of the Database window. If the report is already opened, to display it in Design View, as done for the form, you can click the View button on the toolbar. You can also click View -> Design on the main menu. To programmatically open a report, you can call the OpenReport() method of the DoCmd object. Its syntax is: DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs) The first argument of this method is the name of the report that you want to open. The second argument is a constant value that can be one of the following:
This third argument, optional, is the name of a query in the database. The fourth argument, also optional, allows you to specify what record would be printed. If you omit this argument, all records of the Record Source value of the report would be printed. If you want to print only one or a few selected records, you can create a WHERE statement and pass it as this argument. The fifth argument specifies how the report should be displayed. It is a constant value that can be acDialog, acHidden, acIcon, or acWindowNormal. This argument is almost never used as it has little to no effect. In most cases, instead of writing the code manually, you can use the Command Button Wizard to select the report to print and how you want the process to be done.
After using a report, you (or the user) can close it. To close a report, you can click its system Close button or . You can also double-click its System button on the left side of its title bar. You can also press Ctrl + F4. When you (or the user) closes a report, if its design has been changed since it was opened, you (or the user) would be prompted whether to save it or ignore the changes. To programmatically close a report, you can call the Close() method of the DoCmd object whose syntax is the same we saw for a form. Here is an example: Private Sub cmdCloseStafMembers_Click() DoCmd.Close acReport, "StaffMembers", acSavePrompt End Sub When this code runs, if a report named StaffMembers is opened, it would be closed. If there is no report opened by that name, nothing would happen (Nice!). |
|
||
Previous | Copyright © 2005-2012, FunctionX, Inc. | Next |
|