'Add a command button and a Crystal Report Viewer Control to you form 'Reference Crystal Reports 8/8.5/9/10 ActiveX Designer Run time Library 'Paste the following code into the form code window 'Change the path "C:\crtests\Report1.rpt" to suit yours Private Sub Command1_Click() Dim CrxApp As CRAXDRT.Application Dim CrxRep As CRAXDRT.Report Dim crxDatabase As CRAXDRT.Database Dim crxDatabaseTables As CRAXDRT.DatabaseTables Dim crxDatabaseTable As CRAXDRT.DatabaseTable Set CrxApp = New CRAXDRT.Application Set CrxRep = CrxApp.OpenReport("H:\test\crtests\Report1.rpt") 'Set your Database object to the Report object's Database object Set crxDatabase = CrxRep.Database 'Set your DatabaseTables object to the Database object's Tables object Set crxDatabaseTables = crxDatabase.Tables 'Loop through each DatabaseTable object in the DatabaseTables collection and then set the location 'of the database file for each table For Each crxDatabaseTable In crxDatabaseTables 'If you are using physical path of the access database file (Native connection to PC database) crxDatabaseTable.Location = App.Path & "\xtremelite.mdb" 'Use next line, if you are using Native connection to SQL database 'crxDatabaseTable.SetLogOnInfo "servername", "databasename", "userid", "password" 'Use next line, if you are using ODBC connection to a PC or SQL database 'HERE IS ACCTUALLY THE ANSWER OF MY QUESTION 'crxDatabaseTable.SetLogOnInfo "ODBC_DSN", "databasename", "userid", "password" Next crxDatabaseTable CRViewer91.ReportSource = CrxRep CRViewer91.ViewReport Set crxDatabase = Nothing Set crxDatabaseTable = Nothing Set crxDatabaseTables = Nothing Set crxReport = Nothing Set crxApplication = Nothing End SubMaybe this could be uselful for somebody looking for the same
DO WHILE .T. ME.Work() ENDDO