| Chapter 5 API Reference |
Represents the WDReportCom. WDReport is the main class for report generation using WDReportCom.
Using the WDReport Object
The following example creates an WDReport object in another application and then generates a report using a WRF file.
Dim wdrpt As WDReport Set wdrpt = New WDReport wdrpt.WordReport wdApp, "customer_list.wrf"
Generates a fixed table report based on a template. In a fixed table report, the number of rows and columns is fixed. WDReportCom gets data from a recordset object, and directly fills data into the cells of a table.
Syntax
object.FixTableReport(Recordset, Table, CellList, Range, FillOrder, ImageList, PageBreak)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Table Required. An object variable that represents the Word.Table object to be filled data.
CellList Required. A string that represents the list of cells separated by the "," character. For example, "A2,B2,B3,D2,D3". The cells in the CellList should correspond to the data source fields in the recordset. The value of the first field is put into the first cell, and the value of the second field is put into the second cell ......
Range Optional. A string that indicates the range in the table to be used for the records. WDReportCom will skip or repeat the range for each record. A range is composed of some rows or columns. You can reference a range of cells like "2:4" or "B:D". The default range is the area that includes all cells for the records.
FillOrder Optional. An integer that indicates the order in which WDReportCom fills data. If the value is zero, fills data by rows. Otherwise fills data by columns. Default is 0.
ImageList Optional. A string that indicates which data source fields are the picture files. The ImageList is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In data source, you stored the path and file name of the picture, not the picture. The file path can be a relative path, an absolute path or a URL. If it is a relative path, the base path is the path of the document.
PageBreak Optional. A string that indicates the page breaks. The unit of page length is r that means record. For example, "6r" or "6" means that WDReportCom will insert a page break per 6 records. Default is "" that means no page break.
Example
This example uses FixTableReport method to make the report "Top 5 Employees for Sales".
1. Create the template in Microsoft Word.
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = "SELECT TOP 5 e.FirstName + ' ' + e.LastName, SUM(d.Quantity),
Sum(d.UnitPrice * d.Quantity * (1-d.Discount)) AS SalesAmount
FROM Orders o, OrderDetails d, Products p, Employees e
WHERE o.OrderID = d.OrderID AND d.ProductID = p.ProductID
AND o.EmployeeID = e.EmployeeID AND YEAR(o.OrderDate) = 1996
AND MONTH(o.OrderDate) = 04
GROUP BY e.FirstName, e.LastName ORDER BY 3 DESC"
rec.Open strSQL, con
wdrpt.FixTableReport Recordset:=rec, Table:=wdTable, CellList:="B2"
rec.Close
3. Generate the report.
Generates a variable table report based on a template. In a variable table report, the number of rows or columns in the table is unfixed, and it is variable as the number of the result records. WDReportCom gets data from a recordset object, inserts some blank rows/columns or copy a range for each record, then fills data into the cells of a table.
Syntax
object.VarTableReport(Recordset, Table, CellList, Range, Copy, Reserve, FillOrder, ImageList, PageBreak, NoData)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Table Required. An object variable that represents the Word.Table object to be filled data.
CellList Required. A string that represents the list of cells separated by the "," character. For example, "A2,B2,B3,D2,D3". The cells in the CellList should correspond to the data source fields in the recordset. The value of the first field is put into the first cell, and the value of the second field is put into the second cell ......
Range Optional. A string that indicates the range in the table to be used for the records. WDReportCom will repeat the range for each record. A range is composed of some rows or columns. You can reference a range of cells like "2:4" or "B:D". The default range is the area that includes all cells for the records.
Copy Optional. An integer that indicates whether WDReportCom will copy the range for each record. If the value is zero, WDReportCom will insert the blank rows/columns of the range for each record. Otherwise it will copy the source range and insert the copied range for each record. Note: WDReportCom will use clipboard. You can not copy and paste during report generating.
Reserve Optional. An integer that indicates the number of records for which you reserved some rows/columns in the report template for the report. Possible values are 1 or 2. One means you reserve some rows/columns for one record, and two means some rows/columns for two records. Default is 1.
FillOrder Optional. An integer that indicates the order in which WDReportCom fills data. If the value is zero, fills data by rows. Otherwise fills data by columns. Default is 0.
ImageList Optional. A string that indicates which data source fields are the picture files. The ImageList is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In data source, you stored the path and file name of the picture, not the picture. The file path can be a relative path, an absolute path or a URL. If it is a relative path, the base path is the path of the document.
PageBreak Optional. A string that indicates the page breaks. The unit of page length is r that means record. For example, "6r" or "6" means that WDReportCom will insert a page break per 6 records. Default is "" that means no page break.
NoData Optional. An integer that represents an option when no data are returned from data source. If the value is 1, WDReportCom will delete the range when no data are returned. If the value is 2, it will delete the table. Default is 0. It means to do nothing.
Example
This example uses VarTableReport method to make the report "Mail Label".
1. Create the template in Microsoft Word.
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = "SELECT CompanyName, Address, CityName & ', ' & CountryName, PostalCode
FROM Customers, Cities, Countries
WHERE Customers.CityCode = Cities.CityCode
AND Customers.CountryCode = Cities.CountryCode
AND Customers.CountryCode = Countries.CountryCode
ORDER BY CompanyName"
rec.Open strSQL, con
wdrpt.VarTableReport Recordset:=rec, Table:=wdTable, _
CellList:="B7,B8,B9,B10", Range:="1:11", Copy:=1, PageBreak:="4r"
rec.Close
3. Generate the report.
Generates a variable table report based on a template, and groups data in the report. In a variable table report, the number of rows or columns in the table is unfixed, and it is variable as the number of the result records. WDReportCom gets data from a recordset object, copy the group range for each group, and copy the detail range for each record.
Syntax
object.GroupTableReport(Recordset, Table, CellList, Range, Copy, FillOrder, ImageList, PageBreak, NoData, Group1, GroupRange1, ... Group10, GroupRange10)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Table Required. An object variable that represents the Word.Table object to be filled data.
CellList Required. A string that represents the list of cells separated by the "," character. For example, "A2,B2,B3,D2,D3". The cells in the CellList should correspond to the data source fields in the recordset. The value of the first field is put into the first cell, and the value of the second field is put into the second cell ......
Range Optional. A string that indicates the range in the table to be used for the records. WDReportCom will repeat the range for each record. A range is composed of some rows or columns. You can reference a range of cells like "2:4" or "B:D". The default range is the area that includes all cells for the records.
Copy Optional. An integer that indicates whether WDReportCom will copy the range for each record. If the value is zero, WDReportCom will insert the blank rows/columns of the range for each record. Otherwise it will copy the source range and insert the copied range for each record. In general, inserting rows/columns is faster than copying range.
FillOrder Optional. An integer that indicates the order in which WDReportCom fills data. If the value is zero, fills data by rows. Otherwise fills data by columns. Default is 0.
ImageList Optional. A string that indicates which data source fields are the picture files. The ImageList is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In data source, you stored the path and file name of the picture, not the picture. The file path can be a relative path, an absolute path or a URL. If it is a relative path, the base path is the path of the document.
PageBreak Optional. A string that indicates the page breaks. The unit of page length is r or g. "r" means record, "g1" means group one, "g2" means group two...... For example, "6r" or "6" means that WDReportCom will insert a page break per 6 records, "1g1" or "1g" means a page break per group one, and "1g1,6r" means a page break per group one or 6 records. Default is "" that means no page break.
NoData Optional. An integer that represents an option when no data are returned from data source. If the value is 1, WDReportCom will delete the range when no data are returned. If the value is 2, it will delete the table. Default is 0. It means to do nothing.
Group1...Group10 Optional. A string that indicates the group that is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In one report, there may be up to 10 groups. Notes: the order of groups should be in accordance with the order of ORDER BY clause in the SQL statement.
GroupRange1...GroupRange10 Optional. A string that indicates the range of the group in the table. WDReportCom will repeat the range for each group. The range of the group should contain the range of the details and the area that includes all cells for this group. You reference a group range like "2:4" or "B:D". For example, there are two groups, the range of the group one contains all cells for the group one and the range of the group two, and the range of the group two contains all cells for the group two and the range of the details. The default range is the area that includes all cells for this group and the range or the group range for the lower level group.
Remarks
GroupTableReport method will use clipboard. You can not copy and paste during report generating.
Example
This example uses GroupTableReport method to make the report "Customer Profile".
1. Create the template in Microsoft Word.
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = "SELECT LEFT(CompanyName,1), CompanyName, ContactName
, 'Phone: ' & Phone, 'Fax: ' & Fax, Address
, CityName & ', ' & CountryName, PostalCode
FROM Customers, Cities, Countries
WHERE Customers.CityCode = Cities.CityCode
AND Customers.CountryCode = Cities.CountryCode
AND Customers.CountryCode = Countries.CountryCode
ORDER BY CompanyName"
rec.Open strSQL, con
wdrpt.GroupTableReport Recordset:=rec, Table:=wdTable, _
CellList:="A2,B3,C3,D3,D4,E3,E4,E5", Copy:=1, _
Range:="2:5", Group1:="1", PageBreak:="5r"
rec.Close
3. Generate the report.
Generates a form report based on a template, and groups data in the report. For a form report, you can put data from data source as text, list, title and table in the report file. WDReportCom gets data from a recordset object, copy the group range for each group, and copy the detail range for each record.
Syntax
object.FormReport(Recordset, Document, CellList, Range, ImageList, PageBreak, NoData, Group1, GroupRange1, ... Group10, GroupRange10)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Document Required. An object variable that represents the Word.Document object to be filled data.
CellList Required. A string that represents the list of merge fields or quote fields separated by the "," character. For example, "ProductName,ProductID,QuantityPerUnit,UnitPrice". The merge fields or quote fields in the celllist should correspond to the data source fields in the SQL statement. The value of the first data source field is put into the first merge field or quote field, and the value of the second data source field is put into the second merge field or quote field ......
Range Optional. A string that indicates the range to be used for the records. WDReportCom will repeat the range for each record. A range is defined by a bookmark. You reference a range using a bookmark name. The default range is the group range or the entire document.
ImageList Optional. A string that indicates which data source fields are the picture files. The ImageList is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In data source, you stored the path and file name of the picture, not the picture. The file path can be a relative path, an absolute path or a URL. If it is a relative path, the base path is the path of the table.
PageBreak Optional. A string that indicates the page breaks. The unit of page length is r or g. "r" means record, "g1" means group one, "g2" means group two...... For example, "6r" or "6" means that WDReportCom will insert a page break per 6 records, "1g1" or "1g" means a page break per group one, and "1g1,6r" means a page break per group one or 6 records. Default is "" that means no page break.
NoData Optional. An integer that represents an option when no data are returned from data source. If the value is not zero, WDReportCom will delete the range when no data are returned. Default is 0.
Group1...Group10 Optional. A string that indicates the group that is the list of data source fields separated by the "," character. You can identify a field using the name of field or the index number of field, but not simultaneously. In one report, there may be up to 10 groups. Notes: the order of groups should be in accordance with the order of ORDER BY clause in the SQL statement.
GroupRange1...GroupRange10 Optional. A string that indicates the range of the group. WDReportCom will repeat the range for each group. A range is defined by a bookmark. You reference a range using a bookmark name. The range of the group should contain the range of the details and the area that includes all merge fields or quote fields for this group. For example, there are two groups, the range of the group one contains all merge fields or quote fields for the group one and the range of the group two, and the range of the group two contains all merge fields or quote fields for the group two and the range of the details. The default range is the range of the upper level group or the entire document.
Remarks
FormReport method will use clipboard. You can not copy and paste during report generating.
Example
This example uses FormReport method to make the report "Product Catalog".
1. Create the template in Microsoft Word.
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = " SELECT CategoryName,Description,ProductName
,ProductID,QuantityPerUnit,UnitPrice
FROM Products, Categories
WHERE Products.CategoryID = Categories.CategoryID
ORDER BY 1,3"
rec.Open strSQL, con
wdrpt.FormReport Recordset:=rec, Document:=wdDoc, _
CellList:="CategoryName,Description,ProductName, _
ProductID,QuantityPerUnit,UnitPrice", Range:="Product", _
Group1:="1,2", GroupRange1:="Category"
rec.Close
3. Generate the report.
Generates a chart based on a template using Microsoft Graph. WDReportCom gets data from a recordset object, and fills data into the datasheet of a chart in the report file.
Syntax
object.MSGraphChart(Recordset, Chart, CellList, Range, FillOrder)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Chart Required. An object variable that represents the Graph.Chart object.
CellList Required. A string that represents the list of cells separated by the "," character. For example, "A2,B2,B3,D2,D3". The cells in the CellList should correspond to the data source fields in the recordset. The value of the first field is put into the first cell, and the value of the second field is put into the second cell ...... Note: On the datasheet, the leftmost column and the top row, which are commonly used for legend text or axis labels, are referred to as column 0 (zero) and row 0 (zero).
Range Optional. A string that indicates the range in the datasheet to be used for the records. WDReportCom will skip the rows/columns of the range for each record. A range is composed of some rows or columns. You can reference a range of cells like "2:4" or "B:D". The default range is the area that includes all cells for the records.
FillOrder Optional. An integer that indicates the order in which WDReportCom fills data. If the value is zero, fills data by rows. Otherwise fills data by columns. Default is 1.
Example
This example uses MSGraphChart method to make the report "Sales by Categories".
1. Create the template in Microsoft Word.
The datasheet of the chart defined in the report template:
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = " SELECT c.CategoryName,
Sum(d.UnitPrice * d.Quantity * (1-d.Discount))
FROM Orders o, OrderDetails d, Products p, Categories c
WHERE o.OrderID = d.OrderID AND d.ProductID = p.ProductID
AND p.CategoryID = c.CategoryID AND YEAR(o.OrderDate) = 1996
AND MONTH(o.OrderDate) = 04
GROUP BY c.CategoryName ORDER BY c.CategoryName"
rec.Open strSQL, con
wdrpt.Chart Recordset:=rec, Chart:=wdChart, CellList:="A0"
rec.Close
3. Generate the report.
The datasheet of the chart generated in the report:
The chart generated in the report:
Generates a chart based on a template using Microsoft Excel. WDReportCom gets data from a recordset object, and fills data into the worksheet of a chart in the report file.
Syntax
object.ExcelChart(Recordset, Workbook, CellList, ReportType, Range, FillOrder)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data. Before calling this method, please keep the current record position to the first record.
Workbook Required. An object variable that represents the Excel.Workbook object.
CellList Required. A string that represents the list of cells separated by the "," character. For example, "A2,B2,B3,D2,D3". The cells in the CellList should correspond to the data source fields in the recordset. The value of the first field is put into the first cell, and the value of the second field is put into the second cell ......
ReportType Optional. An integer that indicates the report type. If the value is zero, WDReportCom will add some blank rows/columns before filling data values into the worksheet of the chart. If the value is one, WDReportCom will directly fill data vales into the worksheet of the chart. Default is 0. When it is a variable table report, you should reserve two rows/columns in the worksheet in the report template, and set the data range of the chart to 2 rows/columns.Range Optional. A string that indicates the range in the datasheet to be used for the records. WDReportCom will skip the rows/columns of the range for each record. A range is composed of some rows or columns. You can reference a range of cells like "2:4" or "B:D". The default range is the area that includes all cells for the records.
FillOrder Optional. An integer that indicates the order in which WDReportCom fills data. If the value is zero, fills data by rows. Otherwise fills data by columns. Default is 0.
Example
This example uses ExcelChart method to make the report "Sales by Categories".
1. Create the template in Microsoft Word.
The worksheet of the chart defined in the report template:
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = " SELECT c.CategoryName,
Sum(d.UnitPrice * d.Quantity * (1-d.Discount))
FROM Orders o, OrderDetails d, Products p, Categories c
WHERE o.OrderID = d.OrderID AND d.ProductID = p.ProductID
AND p.CategoryID = c.CategoryID AND YEAR(o.OrderDate) = 1996
AND MONTH(o.OrderDate) = 04
GROUP BY c.CategoryName ORDER BY c.CategoryName"
rec.Open strSQL, con
wdrpt.Chart Recordset:=rec, Workbook:=wdWorkbook, CellList:="A2"
rec.Close
3. Generate the report.
The worksheet of the chart generated in the report:
The chart generated in the report:
Gets data from a recordset object, and assigns the values to the names defined in the Word document. WDReportCom will just fetch the first record, no matter how many records are returned from data source.
Syntax
object.SetDocVariable(Recordset, Document, NameList)
object Required. The object is the WDReport object.
Recordset Required. An object variable that represents the ADODB.Recordset object to provides data.
Document Required. An object variable that represents the Word.Document object to be filled data.
NameList Required. A string that represents the name of the document variables you want assign values to. The NameList is the list of variable names separated by the "," character. For example, "BeginDate, EndDate" means two document variables: BeginDate and EndDate that should be defined in the report template. The variables in the list should correspond to the fields in the SQL statement. The value of the first field is put into the first variable, and the value of the second field is put into the second variable ...
Remarks
SetDocVariable method supports headers and footers. You can use it to put data into headers or footers.
WDReportCom can not update the docvariable fields automatically. To show the results, you should update the fields. For example,
' Update all fields in the document wdDoc.Fields.Update ' Update all fields in the primary header of section 1. wdDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update
Example
This example uses SetDocVariable method to assign the values of fields to document variables.
1. Define the document variables BeginDate and EndDate in the report template in Microsoft Word.
2. Write the code in your application.
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.ConnectionString = "Data Source=Report Sample"
con.Open
strSQL = " SELECT min_date, max_date FROM tmp0"
rec.Open strSQL, con
wdrpt.SetDocVariable Recordset:=rec, Document:=wdDoc, NameList:="BeginDate,EndDate"
rec.Close
wdDoc.Fields.Update
Generates the reports based on the templates and a WRF file. The WRF file tells WDReportCom how to get data from data sources and how to put data into the reports.
Syntax
object.WordReport(Application, WrfFile, Param1 ... Param10)
object Required. The object is the WDReport object.
Application Required. An object variable that represents the Word.Application object.
WrfFile Required. A string that represents the WRF file. You can include a full path.
Param1 ... Param10 Optional. A string that represents the paramters. These parameters have been defined in the WRF file.
Example
This example uses WordReport method to make the report "Customer List".
1. Create the template customer_list.doc using Microsoft Word.
2. Create the WRF file customer_list.wrf using a text editor.
3. Write the code in your application.
Set wdApp = New Word.Application
Set wdrpt = New WDReport
Call wdrpt.WordReport(wdApp, "customer_list.wrf")
Returns a Word.Table object by using the table index.
Syntax
object.GetTableByIndex(Document, Index)
object Required. The object is the WDReport object.
Document Required. An object variable that represents the Word.Document object.
Index Required. A string that represents the index of the table. The index number starts at 1. For examples, table 2 is the second table in the document. The index number of a nested table likes 2-1-2. For examples, table 2-1 is the first table inside table 2, and table 2-1-2 is the second table inside table 2-1. The max nested level WDReportCom supports is 3.
Example
This example uses GetTableByIndex method to get the first table in the document.
Dim wdDoc As Word.Document
Dim wdTable As Word.Table
......
Set wdTable = mwdrpt.GetTableByIndex(wdDoc, "1")
Returns a Word.Table object by using the bookmark.
Syntax
object.GetTableByBookmark(Document, Bookmark)
object Required. The object is the WDReport object.
Document Required. An object variable that represents the Word.Document object.
Bookmark Required. A string that represents the name of the bookmark that is in the table. You can reference a nested table. The max nested level WDReportCom supports is 3.
Example
This example uses GetTableByBookmark method to get the table in the document.
Dim wdDoc As Word.Document
Dim wdTable As Word.Table
......
Set wdTable = mwdrpt.GetTableByBookmark (wdDoc, "MyTable")
Returns a Word.OLEFormat object that represents the Microsoft Graph chart or Microsoft Excel chart OLE object.
Syntax
object.GetChartByIndex(Document, Index)
object Required. The object is the WDReport object.
Document Required. An object variable that represents the Word.Document object.
Index Required. A string that represents the index of the chart. The index number starts at 1. For examples, chart 2 is the second chart in the document.
Example
This example uses GetChartByIndex method to get the object of the first chart in the document.
Dim wdDoc As Word.Document
Dim wdChartOLE As Word.OLEFormat
Dim graChart As Graph.Chart
Dim xlWorkbook As Excel.Workbook
......
Set wdChartOLE = mwdrpt.GetChartByIndex(wdDoc, "1")
If Left(wdChartOLE.ProgId, 11) = "Excel.Chart" Then
Set xlWorkbook = wdChartOLE.object
Else
Set graChart = wdChartOLE.object
End If
Returns a Word.OLEFormat object that represents the Microsoft Graph chart or Microsoft Excel chart OLE object.
Syntax
object.GetChartByIndex(Document, Bookmark)
object Required. The object is the WDReport object.
Document Required. An object variable that represents the Word.Document object.
Bookmark Required. A string that represents the name of the bookmark that includes the chart.
Example
This example uses GetChartByBookmark method to get the object of the chart in the document.
Dim wdDoc As Word.Document
Dim wdChartOLE As Word.OLEFormat
Dim graChart As Graph.Chart
Dim xlWorkbook As Excel.Workbook
......
Set wdChartOLE = mwdrpt.GetChartByBookmark(wdDoc, "Chart1")
If Left(wdChartOLE.ProgId, 11) = "Excel.Chart" Then
Set xlWorkbook = wdChartOLE.object
Else
Set graChart = wdChartOLE.object
End If
Occurs before a connection starts.
Syntax
Private Sub object_BeforeConnect(UserID As String, Password As String, DataSource As String, Connection As ADODB.Connection)
object The object is the WDReport object.
UserID A string that represents a user name for the connection.
Password A string that represents a password for the connection.
DataSource A string that represents a data source name for the connection.
Connection The ADODB.Connection object.
Example
Private Sub mwdrpt_BeforeConnect(UserID As String, Password As String, _
DataSource As String, Connection As ADODB.Connection)
Connection.ConnectionTimeout = 15
Connection.CursorLocation = adUseClient
End Sub
Occurs when a template document is opened.
Syntax
Private Sub object_TemplateOpen(ByVal Document As Word.Document)
object The object is the WDReport object.
Document An object variable that represents the Word.Document object to be opened.
Example
Private Sub mwdrpt_TemplateOpen(ByVal Document As Word.Document)
gstrFileName = Document.FullName
End Sub
Occurs when all report generating process is completed.
Syntax
Private Sub object_ReportComplete(ByVal Document As Word.Document)
object The object is the WDReport object.
Document An object variable that represents the Word.Document object.
Example
Private Sub mwdrpt_ReportComplete(ByVal Document As Word.Document)
' Close the document and do not display the report when get errors
If mintErrCount > 0 Then
Document.Close
End If
End Sub
Occurs before a function is executed.
Syntax
Private Sub object_FunctionBeforeExectue(ByVal FunctionNo As String, ByVal FunctionType As Integer, ByVal SQLNo As Long, ByVal SQLText As String)
object The object is the WDReport object.
FunctionNo A string that represents the label of the function.
FunctionTyp An integer that represents the type of the function. 0 means ExecSQL function. 1 means DocVariable function. 2 means Report function. 3 means Chart function.
SQLNo A long that represents the number of SQL statements.
SQLText A string that contains the SQL statement.
Example
Private Sub mwdrpt_FunctionBeforeExectue(ByVal FunctionNo As String, _
ByVal FunctionType As Integer, ByVal SQLNo As Long, _
ByVal SQLText As String)
frmWait.lblFunctionNo = FunctionNo
frmWait.lblSQLCount = SQLNo
End Sub
Occurs after a function is executed.
Syntax
Private Sub object_FunctionAfterExectue(ByVal FunctionNo As String, ByVal FunctionType As Integer, ByVal SQLNo As Long, ByVal ErrObj As ErrObject)
object The object is the WDReport object.
FunctionNo A string that represents the label of the function.
FunctionTyp An integer that represents the type of the function. 0 means ExecSQL function. 1 means DocVariable function. 2 means Report function. 3 means Chart function.
SQLNo A long that represents the number of SQL statements.
ErrObj The Err object.
Example
Private Sub mwdrpt_FunctionAfterExectue(ByVal FunctionNo As String, _
ByVal FunctionType As Integer, ByVal SQLNo As Long, _
ByVal ErrObj As ErrObject)
If ErrObj.Number <> 0 Then
If FunctionType <> 0 Then 'Ignore errors of EXECSQL
MsgBox ErrObj.Description, vbExclamation, App.ProductName
mintErrCount = mintErrCount + 1
End If
End If
End Sub
Occurs periodically during a function processing.
Syntax
Private Sub object_FunctionProgress(ByVal Progress As Long, ByVal RecordCount As Long)
object The object is the WDReport object.
Progress A long that indicates the number of records that have currently been processed.
RecordCount A long that indicates the total number of records.
Example
Private Sub mwdrpt_FunctionProgress(ByVal Progress As Long, _
ByVal RecordCount As Long)
frmWait.lblRecordCnt.Caption = Format(Progress, "#,##0") & _
" / " & Format(RecordCount, "#,##0")
End Sub
The following table lists the trappable errors for the WDReport Object.
| Value | Description |
| -2147221493 | The file WrfFileName does not exist. |
| -2147221492 | The file WrfFileName is not a WordReport file. |
| -2147221491 | Error in reading the file WrfFileName. |
| -2147221490 | Report template file TemplateFileName does not exist. |
| -2147221489 | The report file is not named correctly. |
| -2147221488 | Failed to create the report file ReportFileName. |
| -2147221487 | Failed to open the template file TemplateFileName. |
| -2147221486 | Failed to save the report file. |
| -2147221485 | Failed to save the report file. Not support the file format: FileFormat. |
| -2147221484 | Failed to update Word fields. |
| -2147221473 | The ADODB.Recordset object is closed. |
| -2147221453 | Syntax error. The table Table does not exist. |
| -2147221452 | Syntax error. The chart Chart does not exist. |
| -2147221451 | The Word.Document object is not set. |
| -2147221450 | The Word.Table object is not set. |
| -2147221449 | The Graph.Chart object is not set. |
| -2147221448 | The Excel.Workbook object is not set. |
| -2147221447 | Unable to find the Word document. |
| -2147221446 | Unable to find the Excel chart. |
| -2147221445 | Unable to find the source data worksheet. |
| -2147221403 | Syntax error. There is a lack of the parameter "NAME". |
| -2147221393 | Syntax error. There is a lack of the parameter "CELL". |
| -2147221392 | Syntax error. It is not a valid cell "" for the parameter "CELL". |
| -2147221391 | Syntax error. Failed to parse cell list. |
| -2147221390 | Syntax error. Failed to parse cell Cell. |
| -2147221389 | Can not find the field Field in the range Range. |
| -2147221383 | The range or copyrange should be Range. |
| -2147221382 | Syntax error. Failed to parse range Range. |
| -2147221373 | Syntax error. Failed to parse image. Can not find field ImageField in the image list. |
| -2147221372 | Syntax error. Failed to parse image. |
| -2147221363 | Syntax error. Failed to parse group Group. Can not find field GroupField. |
| -2147221362 | Syntax error. Failed to parse group. |
| -2147221361 | The grouprange of group N should be Range. |
| -2147221360 | Syntax error. Failed to parse grouprange. |