Hi All,

I am trying to create crystal report 11 with VB6. But it seen like during the execution of code, the sql statement was ignored (line 12). And the report listed out everything. Below is my code.

Dim rs As ADODB.Recordset
Dim strSQL As String

Set Report = New CR_DriverCommission_Rpt
Set rs = New ADODB.Recordset

strSQL = "SELECT SALES_ID, DOC_DATE FROM BTU_SALES_15 WHERE SALES_ID LIKE 'D%'"
rs.Open strSQL, cn, adOpenDynamic, adLockBatchOptimistic

With Report
    .Database.SetDataSource rs
    .PaperOrientation = crDefaultPaperOrientation
    .PaperSize = 2
    .DiscardSavedData
End With

With CRViewer1
    .EnableDrilldown = False
    .DisplayGroupTree = False
    .DisplayTabs = False
    .EnableRefreshButton = True
    .ReportSource = Report
    .ViewReport
    .Zoom (100)
End With

Set Report = Nothing
rs.Close
Set rs = Nothing

Anybody has any idea what went wrong? I am losing hair solving this. :'(
Thank in Advance.

If that is all the code, you appear to be missing a connection object (the cn object located on line 8).

ADD above line 6:

Set cn = new ADODB.Connection
strConnectString = "Driver={SQL Server}; Server=myserver; Database=mydb; UID=sa; PWD=password"
cn.ConnectionString = strConnectString

strConnectString needs to be set to whatever Data source your using.. MSSQL, Access, etc..

Hope that helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.