*!* Define the Crystal Application, Report, Database, DatabaseTables and *!* DatabaseTable objects as global variables public crxApplication public crxReport public crxDatabase public crxDatabaseTables public crxDatabaseTable *!* Assign the Crystal Application and Report objects to their class types. *!* Unlike other development tools you have to assign the report type also SET ASSERTS ON ASSERT .f. crxApplication = createobject("CrystalRuntime.Application") *!* Open the report crxReport = crxApplication.OpenReport("C:\crystal\preview.rpt") ************************************************ * Use the following code if you have a SQL based database, * or a database with a password * Set the Database, DatabaseTables and DatabaseTable objects * crxDatabase = crxReport.Database * crxDatabaseTables = crxDatabase.Tables * crxDatabaseTable = crxDatabaseTables.Item(1) * Pass the database logon information "DSN or ServerName", "DatabaseName", * "UserID", "Password" * crxDatabaseTable.SetLogonInfo ("Server Name","Database","User ID","Password") ***************************************************** *!* If the CRViewer is added to the form, with out any report to preview *!* Visual FoxPro will give an error stating that the "OLECONTROL may be corrupt" *!* This has to do with the drawing method of certain types of controls being designed *!* more specifically for Visual Basic. To get around this add the Smart Viewer *!* to the form when you want to view the report and preview right away. If the *!* preview method is not called you will get an error. scr8_vfp_rdc_preview.AddObject("CRViewer1","olecontrol","CRViewer.CRViewer") *!* Set the viewer to be the size of the form and visible. scr8_vfp_rdc_preview.CRViewer1.width = scr8_vfp_rdc_preview.width scr8_vfp_rdc_preview.CRViewer1.height = scr8_vfp_rdc_preview.height scr8_vfp_rdc_preview.CRViewer1.Visible =.T. *!* Attach the report to the viewer scr8_vfp_rdc_preview.CRViewer1.reportsource = crxReport *!* View the report scr8_vfp_rdc_preview.CRViewer1.ViewReport