Saving and Loading Report Layouts

Reports can be saved and loaded into the designer by a variety of different methods. The easiest method is to use the File menu on the designer to Save or Open RPX files (ActiveReport's standard XML-formatted report files).

Open/Save From File Menu

To save the report created in the previous sample:

  1. Select the File menu.
  2. Select the Save menu option.
  3. Select the project's directory, set the File name to sample report.rpx and select save.

Stop the project and restart is so the designer will return to the default setting. To load the previously created report back into the designer:

  1. Select the File menu.
  2. Select the Open menu option.
  3. Select the sample report.rpx file from the project's directory and select Open.

When the RPX file is loaded, the designer will display the previously created report.

Open/Save Through Code

A designer's layout can be saved and loaded through code by using the following methods:

Saving:

To save a designer layout in code use the designer's SaveToObject method to save the layout to a report object. Once the layout is saved to the report object, the report object's SaveLayout method can be used to save the layout to an RPX file, or byte array. Add the following code to the sample project to save the designer layout whenever the Report Preview tab is selected.

Private Sub prepPreview()
On Error GoTo errHndl
'Writes the designer's layout
'to the report so it can be previewed.
ard.SaveToObject rpt
'Saves the report object to the specified style
rpt.SaveLayout App.Path & "\sample report.rpx", ddSOFile
'Resets report
rpt.Restart
'Run the new report
rpt.Run False
'Add the report to the veiwer
Set arv.ReportSource = rpt
Exit Sub
 
errHndl:
MsgBox "Error Previewing the Report: " & Err.Number & " " & Err.Description
End Sub

Save these changes.

Loading:

To load a designer layout in code use the report object's Load method to load a specified RPX file and the designer's LoadFromObject to read the layout into the designer. Add the following code to the project to load the report designer when the project starts, and whenever the Runtime Designer tab is selected.

Private Sub Form_Load()
'Set active Tab to the designer
SSTab1.Tab = 0
Set rpt = New ActiveReport
'Activate all the toolbars
ard.ToolbarsVisible = ddTBToolBox + ddTBAlignment + ddTBExplorer + _
ddTBFields + ddTBFormat + ddTBMenu + ddTBPropertyToolbox + ddTBStandard
 
ard.ToolbarsAccessible = ddTBToolBox + ddTBAlignment + ddTBExplorer + _
ddTBFields + ddTBFormat + ddTBMenu + ddTBPropertyToolbox + ddTBStandard
'Load the saved RPX file into a report object
rpt.LoadLayout App.Path & "\sample report.rpx"
'Load the report object into the designer
ard.LoadFromObject rpt
End Sub
 
Private Sub prepDesigner()
On Error GoTo errHndl
 
If Not arv.ReportSource Is Nothing Then
arv.ReportSource.Cancel
Set arv.ReportSource = Nothing
End If
 
'Load the saved RPX file into a report object
rpt.LoadLayout App.Path & "\sample report.rpx"
'Load the report object into the designer
ard.LoadFromObject rpt
 
Exit Sub
errHndl:
MsgBox "Error in Design Preview: " & Err.Number & " " & Err.Description
End Sub

Save these changes.

Loading DSR (ActiveX Designer) Files

The run-time designer can also load ActiveReport's ActiveX Designers included within the project. To demonstrate this capability:

  1. Add an ActiveReport ActiveX Designer to the project and set its properties as follows.

    Name rptSample

  2. From the designer's File menu, open the previously saved sample report.rpx file. When the RPX file is opened the ActiveX designer will have the same report that was developed with the runtime designer.
  3. Modify frmMain's Form_Load event to load rptSample instead by adding the following code:

    Private Sub Form_Load()
    'Set active Tab to the designer
    SSTab1.Tab = 0
    Set rpt = New ActiveReport
    'Activate all the toolbars
    ard.ToolbarsVisible = ddTBToolBox + ddTBAlignment + ddTBExplorer + _
    ddTBFields + ddTBFormat + ddTBMenu + ddTBPropertyToolbox + ddTBStandard
     
    ard.ToolbarsAccessible = ddTBToolBox + ddTBAlignment + ddTBExplorer + _
    ddTBFields + ddTBFormat + ddTBMenu + ddTBPropertyToolbox + ddTBStandard
     
    'Load the ActiveX designer into the run-time designer
    ard.LoadFromObject rptSample
     
    End Sub

    Do not save these changes.