|
|
|||
Home Products Downloads Registered users Support Prices Order Primary Subscription |
|
||
Quick StartWhere? form: frmQuickStart; template: QuickStart.xls As stated earlier, to create a report you must first create a report template. Let's open QuickStart.xls. The first thing you will notice is that there are a lot of #NAME? errors (if there isn't enough place for this text Excel replaces it with # signs). This is normal. Pick any such cell and look at the Formula bar. Almost all the formulas include the pattern =DatasourceName_FieldName (the underscore is required) - we call such a pattern a field formula - where DatasourceName is equal to Customers or Orders and FieldName - one of field names of the datasource to be. Since Excel cannot find these cells in the workbook immediately it displays the #NAME? error. Note You can apply any formatting to any workbook cells, insert pictures, and modify any of the parameters of the workbook itself. In this example, we have turned off the zero values display and hidden the gridlines (Tools|Options). Active XL Report will preserve all changes to the template. ![]() To produce a report of all orders for the current customer we have created a specially formatted range - a set of cells in Excel terminology - B11:L15. Looking at the design of the template you can see that certain cells have been merged and some columns have been hidden. The hidden cells D15 and E15 contain the formulas - =Orders_ShipToAddr1 and =Orders_ShipToAddr2 respectively. The values of these cells are used in the formula of cell G15 - = "" & D15 & " " & E15 - to create the full shipping address. As a reminder - it is permissible to use all of the standard Excel formulas as well as functions, references, etc. This report includes a Special tax that is less than the "standard" Tax Rate by the value in cell L4. The formula for this Special tax rate - =I13-L$4 - can be seen in cell J14 (Note the use of $ character in referencing the L4 cell - this is an example of an absolute reference. See Excel Help for details). We have frozen the top horizontal pane just under the report head (Window|Freeze Pane). Then we have added colors to the template. To distinguish the orders honored by Visa cards, we have applied conditional formatting to the G13 cell that contains the payment method - =$G13="Visa". To see this, select this cell and choose Format|Conditional formatting. So, for Visa orders, the field value will be displayed in a different color. The same trick was used for the Special tax cell. As the result, all negative values in this cell are shown in red. As the final step in our work on the template, the A13:L16 range was named OrdersRange. You can find it in the Name box at the left of the Formula bar. Select this name from the Name box and you will see this range selected in the worksheet. Note the empty column at range's left and the empty row below. These cells are used in Active XL Report to describe additional actions that used to manipulate the data. They have been left empty in this example. Why A13:L16? ![]() The Active XL Report setup procedure adds XLReport to the list of available ActiveX controls. We have added this control to the frmQuickStart form and called it ocxXLReport. To set its properties, we have opened its property pages either by selecting Properties in its pop-up menu (VB) or through the Custom property (Access). There must be a link between the XLReport component and the report template. To create the link, we have set the Template property of ocxXLReport to the path and file name of the template. At the property page we have also defined two datasources for the template. The first one is Customers and the second one is Orders. The OrdersRange range defined in the template was assigned to the Orders datasource. That was all with the component. ![]() Note Two buttons - cmdTemplate and cmdReport - were added to the form with the code intended for opening the template and creating the report accordingly. Note
Private Sub cmdTemplate_Click()
Me.ocxXLReport.Edit
End SubPrivate Sub cmdReport_Click()
rstCustomers.Bookmark = Me.dcbCustomer.SelectedItem
End Sub
Me.ocxXLReport.Report Array(rstCustomers, Me.adoOrders.Recordset) The Report method gets an array of ADO Recordsets as a parameter. You can pass also DAO Recordsets, RDO Resultsets and unbound data, all of which will be referred as datasets further on. Test the form by building reports for several customers. Note the report workbook name - it is created by adding serial numbers to the name of a report template. Creating Active XL Report datasources dynamicallyWhere? form: frmQuickStart2; template: QuickStart.xls To demonstrate the use of dynamically created datasources we took the previous form and emptied the XLRDatasources collection of the ocxXLReport component by deleting existing datasources. Then we rewrote the Click event as follows:
Private Sub cmdReport_Click() Dim xlr As axlr.XLReport Dim dsrOrders As axlr.XLRDatasource Dim dsrCustomers As axlr.XLRDatasource
Set xlr = Me.ocxXLReport
End Sub
xlr.Template = ".\Templates\QuickStart.xls" Do While xlr.Datasources.Count <> 0
xlr.Datasources.Delete 0
LoopSet dsrCustomers = xlr.Datasources.Add dsrCustomers.Name = "Customers" Set dsrOrders = xlr.Datasources.Add dsrOrders.Name = "Orders" dsrOrders.Range = "OrdersRange" rstCustomers.Bookmark = Me.dcbCustomer.SelectedItem xlr.Report Array(rstCustomers, Me.adoOrders.Recordset) First, we link the xlr object variable to the ocxXLReport control and set its properties. Second, the Datasources collection is cleared (just a precaution). Then two datasources are added - Customers and Orders. The last one is bound to the OrdersRange range from the template. Then the current record in the rstCustomers recordset is set to reflect user's choice. Finally, the Report method assigns the rstCustomers recordset to the first datasource in the Datasources collection (it's the Customers datasource), the Me.adoOrders.Recordset to the Orders datasource (the second one), and builds a report. Time to look back - quick startTo summarize the topics covered in this section:
|
Components
Data Access methods
Excel version supportedMS Excel 97 (SR2)
[ Download it ] |