The RunReportToFile method runs the specified report, outputting it to the specified file.

Syntax

RunReportToFile(ReportName as String, 
    OutputFileName as String
    [, FileType as String 
    [, FileSubType as String 
    [, Values as String]
    [, CallBack as Object]]]]) as Boolean

Parameters
ReportName
The name of the report to run.

OutputFileName
The name and path of the file to output the report to. If the file already exists, it's overwritten.

FileType
The type of file to create. This is the same as a file extension: "PDF" for a PDF file, "XLS" for a Microsoft Excel file, "DOC" for a Microsoft Word file, "HTML" for an HTML file, and so forth (see the Output Options topic in the Stonefield Query help file for a list of the file types supported). If this parameter isn't passed, the extension of the filename specified in the OutputFileName parameter is used to determine the file type.

FileSubType
Since Stonefield Query can output either data-only or full format for Microsoft Excel or spreadsheets with an XLS extension, specify the type of file you want if you output to XLS: either "full" for full formatted Excel, "data" for data-only Excel, "fast" for fast data-only, or "spreadsheet" for a spreadsheet XLS file.

Values
The values for any ask-at-runtime conditions. If it is passed, this parameter must be specified as an XML string with the following format:

<values>
      <value>First value</value>
      <value>Second value</value>
</values>

Put no space between the opening and closing tags to indicate that a condition should be ignored. For example:

<values>
      <value></value>
</values>

For dates, use the format YYYY-MM-DD. For logical or Boolean fields, use "T", "True", "Y", or "Yes" for True (anything else is considered to be False). For the "is between" or "is one of" operators, separate the values with a comma (for example, "2002-01-01,2002-12-31" for a "Date is between 01/01/2002 and 12/31/2002" condition). Omit the value (that is, use an empty value element) to ignore the condition.

Example:

<values>
      <value>2008-01-01,2008-12-31</value>
</values>

Callback
If you want the ask-at-runtime dialog to appear, you must set the AllowDialogs parameter to "yes". The dialog may appear behind your application's window, with the icon flashing in the Windows TaskBar. Automatically bringing the dialog to the front is a little complicated since recent Windows versions don't allow a window to bring itself to the front. Instead, use a callback object that does it. Here's an example (preceding and error handling code omitted for brevity):

loQuery.SQApplication.Parameters.AddItem('AllowDialogs', 'yes')
loCallBack = createobject('CallBack')
loQuery.SQApplication.ReportEngine.RunReportToFile('Customers', ;
  '\SomeFolder\customers.pdf', , , , loCallBack)

define class CallBack as Custom
  function OnShowWindow(tnHWnd)
    declare integer SetForegroundWindow in user32 integer hwnd
    SetForegroundWindow(tnhWnd)
  endfunc
enddefine

Return Value
True if the report ran successfully and the file was created or False if an error occurred or no records match the filter condition (in that case, check the ErrorMessage property of the ReportEngine object for the reason for failure).

Example
This example runs the Customers report.

Visual FoxPro

loQuery = createobject('SQProxy.SQProxy')
loQuery.LoadProject('\MyProjects\Northwind', 'admin', 'admin')
if loQuery.ProjectLoaded
  llSuccess = loQuery.SQApplication.ReportEngine.RunReportToFile('Customers', ;
    '\MyReports\customers.pdf')
  if not llSuccess
    messagebox(loQuery.SQApplication.ReportEngine.ErrorMessage)
  endif
endif

C#

using SFQWrapper;
using SQProxyWrapper;
using System.IO;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      SQProxy sqProxy = new SQProxy();
      sqProxy.LoadProject(@"\MyProjects\Northwind");

      // Wait for project to finish loading
      while (!sqProxy.ProjectLoaded)
      {
      }

      string fileName = @"\MyReports\customers.pdf";
      bool result = sqProxy.SQApplication.ReportEngine.RunReportToFile("Customers", 
        fileName);
      if(result)
      {
        System.Diagnostics.Process.Start(fileName);
      }
    }
  }
}

VB.NET

Imports SQProxyWrapper
Imports SFQWrapper

Module Module1
  Sub Main()

    Dim sqProxy As SQProxyWrapper.SQProxy = New SQProxyWrapper.SQProxy
    sqProxy.LoadProject("\MyProjects\Northwind")

    ' Wait for project to finish loading
    While Not sqProxy.ProjectLoaded
    End While

    Dim fileName As String = "\MyReports\customers.pdf"
    Dim result As Boolean = 
      sqProxy.SQApplication.ReportEngine.RunReportToFile("Customers", "C:\SQProxyReport.pdf")
    If result Then
      System.Diagnostics.Process.Start(fileName)
    End If
  End Sub
End Module

See also

PrintReport | ReportEngine Object | RunReport | SQProxy Object

© Stonefield Software Inc., 2023 • Updated: 02/05/20
Comment or report problem with topic