Saving And Loading RDF Files
ActiveReports allows reports to be saved into their own standard format called an RDF file (Report Document Format). Once a report has been saved to an RDF file, it can be loaded into the viewer control and used to display reports in custom preview applications and on the web. Below is a sample project demonstrating how to save and load these RDF files.
- Create a new Visual Basic EXE project.
- Change the name of From1 to frmRDFs.
- Create a new ActiveReport, as shown in the first tutorial, and set the report's name to rptRDFs (See Chapter 15).
With frmRDFs
- Add the Data Dynamics ActiveReports Viewer 2.0 control to frmRDFs.
- Add two command buttons below the viewer control and set their properties as follows:
| Name |
cmdSave |
cmdLoad |
| Caption |
Save Report |
Load Report |
| Enabled |
True |
False |
- Add the following code to the cmdSave_Click event:
Private Sub cmdSave_Click()
rptRDFs.Run
rptRDFs.Pages.Save App.Path & "\SavedRDF.RDF"
cmdLoad.Enabled = True
End Sub
- Add the following code to the cmdLoad_Click event:
Private Sub cmdLoad_Click()
ARViewer21.Pages.Load App.Path & "\SavedRDF.RDF"
frmRDFs.Caption = "RDF File loaded: " & App.Path & "\SavedRDF.RDF"
End Sub
With rptRDFs
- Insert a ADO data control in the Detail section.
- Connect to Nwind.mdb (see Chapter 3 for help with connecting).
- Set the data control's source property to the following SQL statement:
SELECT * FROM Employees ORDER BY Title
- Remove the PageHeader/Footer sections from the report.
- Add a GroupHeader/Footer to the report.
- Set the GroupHeader's properties as follows:
| BackColor |
Black |
| BackStyle |
1-Normal |
| CanShrink |
False |
| Height |
330 |
| DataField |
EmployeeID |
| GrpKeepTogether |
2-All |
| KeepTogether |
True |
- Place three fields in the GroupHeader and set their properties as follows:
| Name |
txtEmployeeID |
txtFirstName |
txtLastName |
| Text |
EmployeeID |
FirstName |
LastName |
| DataField |
EmployeeID |
FirstName |
LastName |
| Height |
270 |
270 |
270 |
| Left |
0 |
1440 |
2880 |
| Top |
0 |
0 |
0 |
| Width |
1260 |
1440 |
1440 |
- Set the GroupFooter's properties as follows:
| BackColor |
Black |
| BackStyle |
1-Normal |
| CanGrow |
False |
| Height |
100 |
| KeepTogether |
True |
- Select the Detail section and set the section's properties as follows:
| BackColor |
&H00404040& |
| BackStyle |
Normal |
| CanShrink |
False |
| Height |
1650 |
- Place a Shape control in the Detail Section and set its properties as follows:
| BackColor |
&H00C0C0C0& |
| BackStyle |
1-ddBKNormal |
| Height |
720 |
| Left |
0 |
| Top |
450 |
| Width |
9360 |
- Right-click on the Shape control and select "Send To Back."
- Place eight textboxes in the Detail section and set their properties as follows:
| Name |
txtTitle |
txtHireDate |
txtExtension |
txtHomePhone |
txtAddress |
txtCity |
txtCountry |
txtPostalCode |
| Text |
Title |
HireDate |
Extension |
HomePhone |
Address |
City |
Country |
Postal Code |
| DataField |
Title |
HireDate |
Extension |
HomePhone |
Address |
City |
Country |
Postal Code |
| Height |
270 |
270 |
270 |
270 |
270 |
270 |
270 |
270 |
| Left |
90 |
1620 |
3150 |
90 |
90 |
90 |
1620 |
3060 |
| Top |
90 |
90 |
90 |
1260 |
540 |
810 |
810 |
810 |
| Width |
1440 |
1440 |
1440 |
1440 |
9180 |
1530 |
1440 |
6210 |
| ForeColor |
&H00E0E0E0& |
&H00E0E0E0& |
&H00E0E0E0& |
&H00E0E0E0& |
|
|
|
|
| BackColor |
|
|
|
|
&H00E0E0E0& |
&H00E0E0E0& |
&H00E0E0E0& |
&H00E0E0E0& |
| BackStyle |
|
|
|
|
1-ddBKNormal |
1-ddBKNormal |
1-ddBKNormal |
1-ddBKNormal |
- Save the project and run it.