'Add this code to a form named form1 and module with a CrystalReports Viewer and reference

'----------
for crystal 8.5
'Add this code to a form named form1 with a CrystalReports Viewer and reference
'the Crystal Reports 8.5 ActiveX Designer Run Time Library
'----------

'----------
for crystal 10
'the Crystal Reports ActiveX Designer Run Time Library 10.0
'----------

'--------------------------------------------------------------------
'Form

Option Explicit

Private Sub Form_Load()
strSelect = "your query"

viewReport strSelect, App.Path & "\rptCustomer.rpt"
End Sub


Private Sub Form_Resize()
CRViewer1.Width = ScaleWidth
CRViewer1.Height = ScaleHeight
End Sub

'-------------------------------------------------------------------



'--------------------------------------------------------------------
'MODULE

Option Explicit
Public crApp As New CRAXDRT.Application
Public crRep As CRAXDRT.Report
Public dbTable As CRAXDRT.DatabaseTable
Public strSelect As String

Function viewReport(ByVal strSql As String, ByVal strReportFile As String)
Set crRep = New CRAXDRT.Report
Set crApp = CreateObject("crystalruntime.application")
Set crRep = crApp.OpenReport(strReportFile)

For Each dbTable In crRep.Database.Tables
dbTable.SetLogOnInfo "servername", "databasename", "", ""
Next dbTable


crRep.SQLQueryString = strSql
Form1.CRViewer1.ReportSource = crRep
Form1.CRViewer1.viewReport

Set crRep = Nothing
Set crApp = Nothing

End Function

'---------------------------------------------------------------------