0

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.

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by sinnerFA
0

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.