ADO Reports emu US 20160105 - Axiell Group AB ActiveX Data Objects (ADO) RecordSet object, bypassing...

47
EMu Release Notes ADO Reports EMu 5.0 Document Version 1

Transcript of ADO Reports emu US 20160105 - Axiell Group AB ActiveX Data Objects (ADO) RecordSet object, bypassing...

EMu Release Notes

ADO Reports EMu 5.0

Document Version 1

Contents

S E C T I O N 1 ADOReports 1 

Note 1 

S E C T I O N 2 CrystalReports 3 

How to create a Crystal ADO Report 3 How to modify a Crystal Report to use ADO instead of ODBC 12 

S E C T I O N 3 MicrosoftExcel 23 

How to create an Excel Report using the ADO RecordSet 23 How to create an Excel Report with nested tables using the ADO RecordSet 35 

S E C T I O N 4 Registryentries 41 

Index 43 

ADO Reports

ADO Reports  

1

ADOReportsReportgenerationandperformancehavebeenimprovedwithEMu5.0andit isnowpossibletoreportdirectlytoanOpenDatabaseConnectivity(ODBC)datasourceandtoanActiveXDataObjects(ADO)RecordSetobject,bypassingtheODBCfilteringprocess.

Thenewreportoptionsare:

Crystal Reports: report directly in ODBC format, bypassing the ODBC filteringprocess.

Crystal ADO: report usingADORecordSets for Crystal (which are accessible viaCrystal'sADOconnector).

MicrosoftADO:reportusingADORecordSetsforMicrosoftproducts.

Crystal and Microsoft reports (Excel, Power Point and Word) whichcurrentlyconnecttoanODBCdatasourcecanbemodifiedtouseanADORecordSet.ItremainspossibletocreatereportsbyconnectingdirectlytoanODBCdatasource.

NoteThis document assumes familiarity with Report creation in EMu. Full details aboutReportCreationareavailableintheEMuHelp:WorkingwithEMurecords>Reports.

S E C T I O N 1

Crystal Reports

ADO Reports  

3

CrystalReportsCreatingaCrystalReportusingthenewADORecordSetissimilartocreatingaCrystalreportwithadirectODBCconnection.Themaindifferencesareinselectingthedatasource.Thisdocumentdescribesthedifferences.

HowtocreateaCrystalADOReportInEMu:

1. Searchfororotherwiselistagroupofrecordsonwhichtoreport.

WhendesigningaCrystalADOreporttherecordsinyourinitialrecordsetmusthaveavalueineachfieldtobeincludedinthereport.Ifnot,thefieldnamewillnotappearinthelistofavailablecolumns.Oncethereportisdefined,itdoesnotmatterifarecorddoesnothavevaluesineveryfieldincludedinthereport.

2. ClickReports intheToolbartodisplaytheReportsbox.

3. Click intheReportsbox.TheReportPropertiesboxdisplays.

4. EnteradescriptivenamefortheReportinthetoptextfield.5. SelectCrystalADOReportfromtheTypedroplist:

S E C T I O N 2

Crystal Reports

4  

ADO Reports

6. OntheFieldstab,addthefieldstobeincludedinthereport.

Inthisexamplethefieldsselectedare:

Crystal Reports

ADO Reports  

5

NotethatagroupwascreatedusingtheCreateGroup button.7. Makechangesontheothertabsasrequired.

SeetheEMuHelpfordetailsaboutsettingasortorder,sortoptions,andsecurity.

8. Click .ThenewreportisaddedtotheReportsbox.

9. IntheReportsbox,selectthenewreportandclick torunthereportforthefirsttime.Amessagewilldisplayindicatingthatyourreportdoesnotexistontheserver.ThisistobeexpectedasthereporthasnotyetbeenbuiltinCrystalReports:

10. Click .

Crystal Reports

6  

ADO Reports

Anxmlfileisgeneratedandsavedwiththedatafromyourrecordset.Thelocationofthisfilecanvary,buttypicallyitcanbefoundin:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\e[modulename]Forexample,areportruninthePartiesmodule,willsavethexmldatafileto:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\epartiesTheCrystalReportsDesignerapplicationwillopen.

11. OntheStartPageoftheCrystalReportsDesigner,selectBlankReportundertheNewReportsheading‐OR‐SelectFile>New>BlankReportintheMenubar.TheDatabaseExpertboxdisplays:

Crystal Reports

ADO Reports  

7

12. Double‐clickCreateNewConnectionandclick besideADO.NET(XML):

Crystal Reports

8  

ADO Reports

Thefollowingscreenwilldisplay:

Crystal Reports

ADO Reports  

9

13. ClickthebuttonbesidetheFilePathfieldtolocateandselectthexmldata.xmlfile

createdwhenthereportwasfirstrun(Step9).SeeStep10fordetailsofthelocationofthexmldata.xmlfile.

14. Click toreturntotheDatabaseExpert:

Crystal Reports

10  

ADO Reports

Group 1 containsvalues from fields thatwegrouped in theEMureport in thisexample(seeStep6).Thesefieldsaretablesofvalues(theycanholdmorethanonevalue).Thisdataneedstobeaddedtoourreportusingasub‐report(seetheEMuHelpfordetails).FieldvaluesfromtheCatalogarecontainedinthetablecalledrow.

15. SelectrowandaddittotheSelectedTablespane:

Crystal Reports

ADO Reports  

11

16. Click .

TheCrystalReportDesignerdisplays,readyforyoutodesignyourCrystalreport.SeetheEMuHelpfordetailsofdesigningaCrystalReport.

It is important not to move the xmldata.xml file as this will causeproblemswhensharingthereportwithotherusers.

Crystal Reports

12  

ADO Reports

HowtomodifyaCrystalReporttouseADOinsteadofODBC

TomodifyaCrystalReporttouseADOratherthanODBC:

1. OpentheReportPropertiesdialogforthereport.ThisexampleusesthedefaultreportList (A4).

2. SelectCrystalADOReportfromtheTypedroplist:

Thefieldsforthisreportare:

Crystal Reports

ADO Reports  

13

Twotablesaregeneratedinthisreport.

3. Click andrunthereport.CrystalwillcreatetheADOrecordsetandthefollowingerrorwilldisplay:

4. OpentheCrystalreportintheCrystalReportDesignerandselecttheDatabase>Set

DatasourceLocationmenuoption.TheSetDatasourceLocationdialogwilldisplay:

Crystal Reports

14  

ADO Reports

5. Select Create New Connection in the Replace with pane and click beside

ADO.NET(XML).Thefollowingscreenwilldisplay:

Crystal Reports

ADO Reports  

15

6. ClickthebuttonbesidetheFilePathfieldtolocateandselectthexmldata.xmlfile

createdwhenthereportwasrun.Thelocationofthisfilecanvary,buttypicallyitcanbefoundin:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\e[modulename]Forexample,areportruninthePartiesmodule,willsavethexmldatafileto:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\eparties

7. Click .YouarereturnedtotheSetDatasourceLocationdialog:

Crystal Reports

16  

ADO Reports

NextitisnecessarytomapfieldsfromtheoldODBCdatasourcetothenewADORecordSet.Inthisexampletherearetwotablestomapandonesub‐report.

8. TomaptheoldODBCCatalogfieldstothenewCatalogtable,clickecatalogue_csvintheCurrentDataSourcepaneandthenclicktherow tableintheReplacewithpane.TheUpdatebuttonwillbeenabled.

9. ClicktheUpdatebuttonandtheMapFieldsdialogwilldisplay:

Crystal Reports

ADO Reports  

17

Fieldswiththesamenamewillbemappedautomatically.

10. UnchecktheMatchtypecheckboxtorevealmorefieldsintheUnmappedFieldspane:

Crystal Reports

18  

ADO Reports

11. CompletemappingfieldsintheUnmappedFieldspane.

Inthisexamplewemapecatalogue_keytoecatalogue_keyandirntoirnbyselectingbothfieldstomapandclickingtheMapbutton.Oncemapped,fieldswillbemovedtotheMappedFieldspane:

Crystal Reports

ADO Reports  

19

12. Click whenallfieldsaremapped.

YouarereturnedtotheSetDatasourceLocationdialog.13. Repeat themappingprocess forall fields(in thisexample,mapping fields in the

CreatorD_csvtabletotheADOtableCreatorDetails):

Crystal Reports

20  

ADO Reports

14. OnceallfieldshavebeenremappedinalltablesclickClose.

YouarereturnedtotheCrystaldesignwindow.Ifyourefreshreportdataatthisstageandyouhaveasub‐reportobject,youwillprobablyreceiveanerrorregardingsub‐reportlinks,e.g.:

Crystal Reports

ADO Reports  

21

Click toopentheRecordSelectionFormulaEditor.Changethelinkkeyfield used by the old ODBC table to the link key field referenced by the ADORecordSet:

Thereportshouldnowworkcorrectly.

Microsoft Excel

ADO Reports  

23

MicrosoftExcel

ThefollowingexamplesdemonstratehowtocreateabasicExcelreportusingVBA.PleasenotethatitisnottheintentionofthisdocumenttoteachVBA.Excel2013wasusedtocreatethesereports.

HowtocreateanExcelReportusingtheADORecordSet

WithODBCdatasourcesthereisanoptioninExceltoopenaconnectionwithoutwritingVisualBasiccode.ThisisnotthecasewhenmakingaconnectiontoanADOrecordsetanditisnecessarytowriteVBcode.

S E C T I O N 3

Microsoft Excel

24  

ADO Reports

Step1:CreateanewreportinEMuThisfirstexampleisasimplereportonsinglevaluefieldsfromtheCatalogmodule.TheVBAcodeprovidedinthisexamplewillautomaticallypopulateheadingsandrowdataforeachcolumnselected.

InEMu:

1. Searchfororotherwiselistagroupofrecordsonwhichtoreport.

2. ClickReports intheToolbartodisplaytheReportsbox.

3. Click intheReportsbox.TheReportPropertiesboxdisplays.

4. EnteradescriptivenamefortheReportinthetoptextfield.5. SelectMicrosoftADOReportfromtheTypedroplist:

6. OntheFieldstab,addthefieldstobeincludedinthereport.

Fieldsselectedinthisexampleare:

Microsoft Excel

ADO Reports  

25

7. Makechangesontheothertabsasrequired.

SeetheEMuHelpfordetailsaboutsettingasortorder,sortoptions,andsecurity.

8. Click .ThenewreportisaddedtotheReportsdialogbox.

9. Selectthenewreportandclick torunthereportforthefirsttime.Amessagewilldisplayindicatingthatyourreportdoesnotexistontheserver.ThisistobeexpectedasthereporthasnotyetbeenbuiltinExcel:

10. Click .Anxmlfileisgeneratedandsavedwiththedatafromyourrecordset.Thelocationofthisfilecanvary,buttypicallyitcanbefoundin:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\e[module

Microsoft Excel

26  

ADO Reports

name]Forexample,areportruninthePartiesmodule,willsavethexmldatafileto:C:\Users\[yourusername]\AppData\Local\KESoftware\Reports\epartiesMicrosoftExcelwillopenwithablankworksheetasfollows:

Microsoft Excel

ADO Reports  

27

EnsurethatExcelissetupcorrectly

IftheDevelopertabdoesnotdisplayintheRibbon:

1. ClickFile>Options>CustomizeRibbon.2. WithMainTabs selected fromtheCustomize theRibbondrop list (1), select the

Developercheckbox(2):

Inordertorunthemacrosthatwewillcreatewithourreports,weneedtoensurethattheSecuritylevelinExcelisappropriate:

1. OntheDevelopertab,click .2. Enableallmacros:

Microsoft Excel

28  

ADO Reports

3. Click toclosetheTrustCenter.

4. OntheDevelopertab,click .Thefollowingscreendisplays:

Microsoft Excel

ADO Reports  

29

5. EnsurethattheMicrosoftActiveXDataObjectsLibraryisavailable:5.1. SelectTools>ReferencesintheMenubar

In the References – VBAProject dialog that displays, make sure that thefollowingcheckboxischecked:

Microsoft Excel

30  

ADO Reports

5.2. Click .

Microsoft Excel

ADO Reports  

31

Step2:DesignthereportinExcel1. Double‐clickSheet1intheVBAProjectpane:

2. CopyandpastethefollowingVBcode:

Sub OpenAdoFile() Dim RecordSet As ADODB.RecordSet Dim Worksheet As Excel.Worksheet Dim h As Long Dim col As Long Dim datarow As Long Dim source As String ' Get the persisted record set source = Environ("LocalAppData") & "\KESoftware\ Reports\ecatalogue\xmldata.xml" Set RecordSet = New ADODB.RecordSet RecordSet.Open source, "Provider=MSPersist" ' Get the active page to send the data to Set Worksheet = ThisWorkbook.ActiveSheet Application.Visible = True

Microsoft Excel

32  

ADO Reports

' Put out all of the column headers col = 1 ListColumnNames Worksheet, RecordSet, col ' Print out all the row data While Not RecordSet.EOF col = 1 datarow = datarow + 1 For h = 0 To RecordSet.Fields.count - 1 Worksheet.Cells(datarow + 1, col).Value = RecordSet.Fields(h).Value col = col + 1 Next RecordSet.MoveNext Wend Worksheet.Range("A1").CurrentRegion.Select Worksheet.Columns.AutoFit Set RecordSet = NothingEnd SubPrivate Sub ListColumnNames(ByVal ws As Excel.Worksheet, ByVal rs As ADODB.RecordSet, ByRef col As Long) Dim i As Long ' Loop through the record set pulling out the column names For i = 0 To rs.Fields.count - 1 ws.Cells(1, col).Value = rs.Fields(i).Name col = col + 1 NextEnd Sub

Microsoft Excel

ADO Reports  

33

3. Double‐click ThisWorbook in the VBAProject pane and copy and paste the

followingcode:Sub Workbook_Open()' Load up the ADO FileSheet1.OpenAdoFileEnd Sub

Microsoft Excel

34  

ADO Reports

4. SavethereportanduploadittoyourEMureport(page24)ontheReportTypetab

oftheReportPropertiesbox.

WhenthereportisruninEMu,anExcelreportisgenerated:

Microsoft Excel

ADO Reports  

35

HowtocreateanExcelReportwithnestedtablesusingtheADORecordSet

1. RepeatStep1:CreateanewreportinEMu(page24).Forthisexample,thefollowingfieldswereselected.Notethetwonestedtables‐Creator'sNameandPhysical:

2. InExcel,click ontheDeveloperstab.3. Double‐clickSheet1intheVBAProjectpane:4. CopyandpastethefollowingVBcode:

Microsoft Excel

36  

ADO Reports

Sub Read_XML_Data() Dim rst As ADODB.Recordset Dim Worksheet As Excel.Worksheet Dim i As Long Dim j As Long Dim source As String Dim datarow As Long Dim saverow As Long Dim lastrow As Long Dim col As Long ' These next declaration is a little odd. Its needed in cases where the entire value ' of a nested table is blank. In these cases it is necessary to force a number of columns to be skipped when printing ' out field values. Oddly, as long as a nested table has at least one value, then there is no issue. ' There is only a need to declare one variable for each nested table. ' In this example there are only two nested tables so two declarations are needed ' The value assigned to each variable will depend on the number of fields in that nested table. ' In this example the first nested table is the CreCreatorRef_tab, which has two fields, i.e. NamFirst and NamLast ' and the second nested table, i.e Physical, has 3 fields, i.e. PhyType, PhyHeight and PhyWidth Dim firstnestedtable As Long Dim secondnestedtable As Long Dim nestedtablecount As Long firstnestedtable = 2 secondnestedtable = 3 nestedtablecount = 1 ' Get the persisted record set source = Environ("LocalAppData") & "\KESoftware\Reports\ecatalogue\xmldata.xml" Set rst = New ADODB.Recordset rst.Open source, "Provider=MSPersist"

Microsoft Excel

ADO Reports  

37

' Get the active page to send the data to Set Worksheet = ThisWorkbook.ActiveSheet Application.Visible = True 'Add column labels Worksheet.Cells(1, 1).Select ActiveCell.EntireRow.Insert Worksheet.Cells(1, 1).Value = "Record No" Worksheet.Cells(1, 2).Value = "IRN No" Worksheet.Cells(1, 3).Value = "Title" Worksheet.Cells(1, 4).Value = "Date Created" Worksheet.Cells(1, 5).Value = "Creator First" Worksheet.Cells(1, 6).Value = "Creator Last" Worksheet.Cells(1, 7).Value = "Physical Type" Worksheet.Cells(1, 8).Value = "Physical Length" Worksheet.Cells(1, 9).Value = "Physical Width" col = 1 ' Start printing data from Row 3 datarow = 3 lastrow = datarow While Not rst.EOF col = 1 If datarow < lastrow Then datarow = lastrow End If For j = 0 To rst.Fields.Count - 1 If rst.Fields(j).Type = adChapter Then If rst.Fields(j).Value.BOF Then Worksheet.Cells(datarow, col).Value = "" If nestedtablecount = 1 Then col = col + firstnestedtable nestedtablecount = nestedtablecount + 1 ElseIf nestedtablecount = 2 Then col = col + secondnestedtable nestedtablecount = nestedtablecount + 1 End If Else If rst.Fields(j).Value.EOF Then Worksheet.Cells(datarow, col).Value = "" If nestedtablecount = 1 Then

Microsoft Excel

38  

ADO Reports

col = col + firstnestedtable nestedtablecount = nestedtablecount + 1 ElseIf nestedtablecount = 2 Then col = col + secondnestedtable nestedtablecount = nestedtablecount + 1 End If Else saverow = datarow ListNestedValues Worksheet, rst.Fields(j).Value, col, datarow, lastrow, saverow, nestedtablecount End If End If Else If IsNull(rst.Fields(j).Value) Then Worksheet.Cells(datarow, col).Value = "" Else Worksheet.Cells(datarow, col).Value = rst.Fields(j).Value End If col = col + 1 End If Next rst.MoveNext datarow = datarow + 1 nestedtablecount = 1 Wend 'Closing the recordset. rst.Close 'Release object from memory. Worksheet.Range("A1").CurrentRegion.Select Worksheet.Columns.AutoFit Set rst = Nothing End SubPrivate Sub ListNestedValues(ByVal ws As Excel.Worksheet, ByVal rs As ADODB.Recordset, ByRef col As Long, ByRef datarow As Long, ByRef lastrow As Long, ByRef saverow As Long, ByRef

Microsoft Excel

ADO Reports  

39

nestedtablecount As Long) Dim i As Long Dim j As Long Dim startrow As Long ' Loop through a nested table pulling out the row values j = 0 startrow = saverow While Not rs.EOF max = 1 j = col For i = 0 To rs.Fields.Count - 1 ' Don't print key values If rs.Fields(i).Name <> "ecatalogue_key" And rs.Fields(i).Name <> "CreCreatorRef_key" And rs.Fields(i).Name <> "Physical_key" _ Then If IsNull(rs.Fields(i).Value) Then ws.Cells(startrow + 1, j).Value = "" j = j + 1 Else If rs.Fields(i).Type = adChapter Then ListNestedValues ws, rs.Fields(i).Value, j, datarow, lastrow, saverow, nestedtablecount datarow = startrow Else ws.Cells(startrow, j).Value = rs.Fields(i).Value j = j + 1 End If End If End If Next rs.MoveNext startrow = startrow + 1 Wend If (j > 0) Then col = j End If If startrow > lastrow Then lastrow = startrow End If

Microsoft Excel

40  

ADO Reports

nestedtablecount = nestedtablecount + 1End Sub

5. Double‐click ThisWorbook in the VBAProject pane and copy and paste thefollowingcode:Sub Workbook_Open()' Load up the ADO FileSheet1.Read_XML_DataEnd Sub

6. SavethereportanduploadittoyourEMureport(page24)ontheReportTypetaboftheReportPropertiesbox.

WhenthereportisruninEMu,anExcelreportisgenerated:

Registry entries

ADO Reports  

41

RegistryentriesTheTypeRegistryentryindicateswhichexporttypetouseforeachreportrequest.

TheformatofthisRegistryentryis;

System|Setting|Reports|Type|Crystal CSV|value

value is0or1:

0 Generatesdataintheexistingformat.

1 GeneratesdatainthenewCrystalODBCformat.

Ifthisentryisnotpresent,avalueof0isassumed.

System|Setting|Reports|Type|Crystal ADO|value

value is0or2:

0 Generatesdataintheexistingformat.

2 GeneratesdatainthenewCrystalADOrecordset.

Ifthisentryisnotpresent,avalueof0isassumed.

System|Setting|Reports|Type|Microsoft ADO|value

where:

value is0or3:

0 Generatesdataintheexistingformat.

3 GeneratesdatainthenewMicrosoftADOformat.

Ifthisentryisnotpresent,avalueof0isassumed.

S E C T I O N 4

Index

ADO Reports • 1

Crystal Reports • 3

E Ensure that Excel is setup correctly • 27

How to create a Crystal ADO Report • 3

How to create an Excel Report using the ADO RecordSet • 23

How to create an Excel Report with nested tables using the ADO RecordSet • 35

How to modify a Crystal Report to use ADO instead of ODBC • 12

Microsoft Excel • 23

Note • 1

Registry entries • 41

S Step 1 Create a new report in EMu • 24, 34, 35, 40

Step 2 Design the report in Excel • 31