Exporting

<< Click to Display Table of Contents >>

 

Exporting

For users to select a name and a directory to generate a file, let's open a dialog box.

1.On the AlarmScreen, insert a Command Button and change its Caption property to "Export".

2.Create the next script.

'Export
If Application.ShowFilePicker(False, FileName,"pdf", _
  128, "PDF Files|*.pdf|All Files|*.*") Then
  Set Report = Application.LoadReport("AlarmReport")
  Report.Export "PDF", FileName
End If

 

3.By using AppBrowser, select Viewer's ShowFilePicker method.

Application.ShowFilePicker(Open, FileName, Extension, Flags, Filter)

 

4.As we want to save a file, replace the Open parameter by "False".

5.The FileName parameter must be a script's internal variable, which stores the file name. Replace it by "FileName".

6.In case users do not provide a file extension, we consider what is provided in the Extension parameter. Type "pdf".

7.To display a confirmation message for users if the file already exists, change the Flags parameter to "128".

8.Dialog boxes for files allow filters for an easy search for file types.

File filters

File filters

9.A filter is always a pair of Strings separated by a vertical bar (the "|" character), where the first item is a name displayed to users and the second item is an identification to the operating system.

10.Replace the Filter parameter by the expression "PDF Files|*pdf|All Files|*.*".

11.A file can only be generated if users click Save. If users cancel that action, nothing should happen. At the beginning of the ShowFilePicker command, type "If" and at the end type "Then".

12.To export a Report, select in AppBrowser the Tasks - Load Report - AlarmReport item and, on the right, the Export method.

Set Report = Application.LoadReport("AlarmReport")
Report.Export([ExportFilter], [ExportFileName])

 

13.Replace the ExportFilter parameter by "PDF" and the ExportFileName parameter by the FileName variable, created previously.

14.Test this new application's functionality.

Was this page useful?