The PreviewReport method displays the specified report in the preview window.


PreviewReport(ReportName as String [, Values as String 
    [, CallBack as Object]]) as Boolean

The name of the report to run.

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:

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

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


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.



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.PreviewReport('Customers', , ;

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

Return Value
True if the report was successfully previewed or False if not (in that case, check the ErrorMessage property of the ReportEngine object for the reason for failure; "*" means the user canceled in any ask-at-runtime dialog that may appear).

This example previews the Customers report.

Visual FoxPro

loQuery = createobject('SQProxy.SQProxy')
loQuery.LoadProject('\MyProjects\Northwind', 'admin', 'admin')
if loQuery.ProjectLoaded
  if not loQuery.SQApplication.ReportEngine.PreviewReport('Customers')


using SFQWrapper;
using SQProxyWrapper;
using System.IO;

namespace ConsoleApplication1
  class Program
    static void Main(string[] args)
      SQProxy sqProxy = new SQProxy();

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

      boolean result = sqProxy.SQApplication.ReportEngine.PreviewReport("Customers");
      if not result {
          String result = sqProxy.SQApplication.ReportEngine.ErrorMessage;
          MessageBox.Show("The report failed because " + reason);	


Imports SQProxyWrapper
Imports SFQWrapper

Module Module1
  Sub Main()

      Dim sqProxy As SQProxyWrapper.SQProxy = New SQProxyWrapper.SQProxy

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

      Dim result As Boolean = 
      if not result then
        dim result as String = sqProxy.SQApplication.ReportEngine.ErrorMessage
        MessageBox.Show("The report failed because " + reason)
      end if
  End Sub
End Module

See also

PrintReport | ReportEngine Object | RunReport | RunReportToFile | SQProxy Object

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