1. Crystal Report 9 - xBase http://opentech.leafe.com/viewtopic.php?t=353 with thisform .addobject("oleviewer","olecontrol","crviewer9.crviewer.9.2") .crystal=createobject("CrystalRuntime.Application.9") .crxreport=.crystal.openreport(thisform.reportname) with .crxreport.Database.Tables.Item(1) .SetTableLocation(m.lcPathFile1,juststem(m.lcPathFile1),"") endwith with .oleviewer .left=thisform.left .top=thisform.top .height=thisform.height .width=thisform.width .reportsource=thisform.crxreport .DisplayToolBar=.t. .EnableGroupTree=.t. .EnableProgressControl=.t. .EnableExportButton=.t. .EnableSearchControl=.t. .EnableSearchExpertButton=.t. .DisplayGroupTree=.f. .DisplayTabs=.f. if .f. if thisform.crxreport.printersetupex(0)=0 thisform.crxreport..PrinterSetup(0) thisform.crxreport.printout(.t.) endif else .viewreport() endif endwith endwith Report.PrinterSetup lHwnd gsOrientation = Report.PaperOrientation 'Save orientation into var Printer.Orientation = Report.PaperOrientation Report.SelectPrinter Report.DriverName, Report.PrinterName, Report.PortName gsPrinterName = Report.PrinterName 'Save other settings to vars gsPrinterDriver = Report.DriverName '... gsPortName = Report.PortName '... '... 'Set the report source (if using already opened ADO recordset). 'Report.Database.SetDataSource oRs, 3, 1 '... 'Then you can set the report to whatever the user selected and print out. Report.DisplayProgressDialog = True Report.SelectPrinter gsPrinterDriver, gsPrinterName, gsPortName Report.PaperOrientation = gsOrientation Report.PrintOut True, 1 2. Crystal 9 - ADODB+Parameter Field set safety off m.lcFile="d:\h123.dbf" USE HOHO exclusive insert into HOHO values ( dtoc(date()), time(), sys(3)) copy to (m.lcFile) type fox2x select HOHO zap use in HOHO local xxx xxx=createobject("crviewer","report1.rpt", m.lcFile) xxx.show() delete file (m.lcFile) set safety on return define class crviewer as form height=_screen.height width=_screen.width windowtype=1 * custom properties reportname="" crxreport=NULL crystal=NULL oConn=NULL oRS=NULL procedure init lparameter m.lcReportName1, m.lcPathFile1, m.lcReportName2, m.lcPathFile2 local loItem as CRAXDRT.DatabaseTable thisform.reportname=m.lcReportName1 thisform.caption=m.lcReportName1+"("+m.lcPathFile1+")" with thisform .addobject("oleviewer","olecontrol","crviewer9.crviewer.9.2") .crystal=createobject("CrystalRuntime.Application") .crxreport=.crystal.openreport(thisform.reportname) .oConn=createobject("ADODB.Connection") .oConn.ConnectionString="Provider=VFPOLEDB.1;" ; + "Data Source="+m.lcPathFile1+";" ; + "Password=''" .oConn.open() .oRS=createobject("ADODB.RecordSet") .oRS.Open("select * from "+juststem(m.lcPathFile1),.oConn) loDb=.crxreport.database() loTables=loDb.Tables() loItem=loTables.item(1) loItem.SetDataSource(.oRS) oParam=.crxreport.ParameterFields() m.xxx=oParam.item(1) m.xxx.SetCurrentValue("from foxpro"+ttoc(datetime())) with .oleviewer .left=thisform.left .top=thisform.top .height=thisform.height .width=thisform.width .reportsource=thisform.crxreport .DisplayToolBar=.t. .EnableGroupTree=.t. .EnableProgressControl=.t. .EnableExportButton=.t. .EnableSearchControl=.t. .EnableSearchExpertButton=.t. .DisplayGroupTree=.f. .DisplayTabs=.f. .viewreport() endwith endwith endproc procedure resize with thisform with .oleviewer .left=thisform.left .top=thisform.top .height=thisform.height .width=thisform.width endwith endwith endproc function unload with thisform .crystal=NULL .crxreport=NULL endwith endproc enddefine 3. Crystal 9 - ODBC connection set safety off use haha copy stru to ("c:\h123.dbf") use use ("c:\h123.dbf") alias t_temp insert into t_temp values ( time(), time(), time() ) use in t_temp local xxx xxx=createobject("crviewer","c:\h123.dbf") xxx.show() delete file ("c:\h123.dbf") set safety on return define class crviewer as form height=_screen.height width=_screen.width windowtype=1 * custom properties crxreport=.f. crystal=.f. dsn_name="" temp_dir="" tempfile="" procedure init lparameter m.lcPathFile local loItem as CRAXDRT.DatabaseTable thisform.temp_dir=addbs(justpath(m.lcPathFile)) thisform.tempfile=juststem(m.lcPathFile) with thisform .addobject("oleviewer","olecontrol","crviewer9.crviewer.9.2") .crystal=createobject("CrystalRuntime.Application") .crxreport=.crystal.openreport("report1.rpt") * .crxreport.sqlquerystring=strtran(.crxreport.sqlquerystring,"`haha` `haha`","`h123` `haha`") * m.loTables=.crxreport.database.tables loDb=.crxreport.database() loTables=loDb.Tables() loItem=loTables.item(1) thisform.dsn_name=sys(3) thisform.makedsn() * loItem.Location=m.tempfile * loDb.tables(1).location=juststem(thisform.tempfile) loItem.SetTableLocation(juststem(thisform.tempfile),juststem(thisform.tempfile),"DSN="+thisform.dsn_name) with .oleviewer .left=thisform.left .top=thisform.top .height=thisform.height .width=thisform.width .reportsource=thisform.crxreport .DisplayToolBar=.t. .EnableGroupTree=.t. .EnableProgressControl=.t. .EnableExportButton=.t. .EnableSearchControl=.t. .viewreport() endwith endwith endproc procedure resize with thisform with .oleviewer .left=thisform.left .top=thisform.top .height=thisform.height .width=thisform.width endwith endwith endproc function unload with thisform .crxreport=NULL endwith thisform.removedsn() endproc function makedsn * Here's the example from the MSDN HOWTO article Q171146 * Offsite link to http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q171146 private ODBC_ADD_DSN &&' Add data source private ODBC_CONFIG_DSN &&' Configure (edit) data source private ODBC_REMOVE_DSN &&' Remove data source private vbAPINull &&' NULL Pointer ODBC_ADD_DSN=1 ODBC_CONFIG_DSN=2 ODBC_REMOVE_DSN=3 vbAPINull=0 *'Function Declare * #If WIN32 Then DECLARE LONG SQLConfigDataSource IN ODBCCP32.DLL ; LONG hwndParent, LONG fRequest, ; STRING lpszDriver, STRING lpszAttributes *#Else * Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _ * (ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _ * lpszDriver As String, ByVal lpszAttributes As String) As Integer *#End If LOCAL intRet, strDriver, strAttributes, m.sep m.sep=chr(0) * "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=c:\myvfpdbfolder; * Exclusive=No;Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO *'Set the driver to SQL Server because it is most common. strDriver = "Microsoft Visual Foxpro Driver" *'Set the attributes delimited by null. *'See driver documentation for a complete *'list of supported attributes. strAttributes = "SourceType=DBF" + m.sep strAttributes = strAttributes + "DSN="+thisform.dsn_name + m.sep strAttributes = strAttributes + "SourceDB="+thisform.temp_dir + m.sep strAttributes = strAttributes + "Exclusive=No" + m.sep strAttributes = strAttributes + "Collate=Machine" + m.sep strAttributes = strAttributes + "NULL=NO" + m.sep strAttributes = strAttributes + "DELETED=NO" + m.sep strAttributes = strAttributes + "BACKGROUNDFETCH=NO" + m.sep *'To show dialog, use Form1.Hwnd instead of vbAPINull. intRet = SQLConfigDataSource(vbAPINULL, ODBC_ADD_DSN, strDriver, strAttributes) clear dlls return intRet>0 function removedsn private ODBC_ADD_DSN &&' Add data source private ODBC_CONFIG_DSN &&' Configure (edit) data source private ODBC_REMOVE_DSN &&' Remove data source private vbAPINull &&' NULL Pointer ODBC_ADD_DSN=1 ODBC_CONFIG_DSN=2 ODBC_REMOVE_DSN=3 vbAPINull=0 *'Function Declare * #If WIN32 Then DECLARE LONG SQLConfigDataSource IN ODBCCP32.DLL ; LONG hwndParent, LONG fRequest, ; STRING lpszDriver, STRING lpszAttributes *'Set the driver to SQL Server because most common. strDriver = "Microsoft Visual Foxpro Driver" *'Set the attributes delimited by null. *'See driver documentation for a complete list of attributes. strAttributes = "DSN="+thisform.dsn_name + Chr(0) *'To show dialog, use Form1.Hwnd instead of vbAPINull. intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, strDriver, strAttributes) clear dlls return intRet>0 enddefine 4. * Dan Tallent - iterate the report object clear oCrRT=createobject("CrystalRuntime.Application") oRPT=oCrRT.openreport("report1.rpt") for m.ii=1 to oRPT.sections.count with oRPT.sections.item(m.ii) for m.jj=1 to .ReportObjects.count with .ReportObjects.item[m.jj] ? .Name m.lcClass=upper(left(.name,4)) do case case m.lcClass=="TEXT" ?? "", .text case m.lcClass="SUB" ?? "". subreport.name case m.lcClass="FIEL" ?? "", .field.name endcase endwith endfor endwith endfor oRPT=NULL oCrRT=NULL