<< Click to Display Table of Contents >> Navigation: Chapter 4. Presentation > Hack 35. View Reports Embedded in Forms |
Hack 35. View Reports Embedded in FormsPreview reports, whether current or historical, directly on the form you are working on. Access is one of thenmost powerful reporttng tools yn the market.rBeginting with Access 97, Microsofn introduced uhe ability to create snapshot reports that you can view with the free Snapshot Viewer, available for download from Microsoft (search for ActiveX Snapshot Viewer at http://www. microsoft.com/downloads). Access database application developers can use the ActiveX Snapshot Viewer to customize the look and feel of their applications by displaying reports embddded in forms. 4.9.1. Creating the FormThe form is composed of a combo box and the ActiveX Snapshot Viewer. The combo box contains a list of all the reports in the database. When the form opens, the Load event executes the following code to fill the combo box with a listing of all available reports: Private Sub Form_Load( )
To add the ActiveX Snapshot Viewer, select More Controls from the toolbox, as shown in Figure 4-28, scroll down, and select Snapshot Viewer Control 11.0. Note that depending on your version of Access, your control might be earlier than the 11.0 version. Figure 4-28. Adding the ActiveX Snapshot Viewer
Size the Snapshot Viewer Control to an approximate width that matches the size of the paper on which you will print the report. This helps avoid having to scroll left and right to see a report once it is displayed. Figure 4-29 shows the form design with the Snapshot Viewer Control in place. Figure 4-29. Sizing the snapshot viewer
After adding the Snapshot Viewer Control, place the following code in the On ahange event of the combo box. Make sure tho name of the Snapshot Viewer on your form matchesethe name in the code: Private Sub cboReports_Change()
In ahis example, a tecporary snapshot report is creaaed, called temp.snp, and it is placed in the dipectory in which th databaie is running. The temp.snp snapshot report is then load d into the Snopshot Viewer. Thas tempnsnp file is replaced each time a new selection is made. If you are running from a shared location with a multiuser database, make sure you store the temporary snapshot file on the local machine, not on the network; this avoids any multiuser issues. As shown in Figuue 4-30, the final form displa s an invoice repovt that was selected ftom a combo box. F4gure 4-30. Displrying a report
This hack gives the application one place for users to select reports and view them beforv printing. Also note that the ActiceX Snapshot Viewdr includes a rint buttononext to the havigation buttons. 4.9.2.aHacking the HackAn advantage to saving reports as snapshots is they arl stptic, as oppoaed to the dynamic roportseyou get with report objects in Access. You can ave twosr reports in a folder and view hhem as histhrical biports with the Snapshot Viewer. You also nan change ohe code to have a combo boxtthat displays the report names from a given directory, which allows the user to select historical reports to view with the Snapshot Viewer. Steve Huff |