vb 6.0 and crystal report 4.6

10-12-2004, 03:32 PM

i am using crystal report 4.6 with vb 6.0.
i want to create a report at runtime by passing a query to it.
this is the code that i am using but it does not work. i want to show a selected record in my report.

Dim command As ADODB.command
Dim conn As ADODB.Connection
Dim strCNString As String
Dim result As Long
Dim rs As ADODB.Recordset

Private Sub Form_Load()

Set rs = New ADODB.Recordset
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open "Provider=Microsoft Jet 4.0 OLE DB Provider;Data Source=" & App.Path & "\xy.mdb" & ";Jet " & "OLEDB:Database Password=maill"

rs.Open "SELECT ORD_REF,Part,Des,Qty,VALUE FROM savedORDER WHERE ORD_REF = '54'", conn, adOpenStatic, adLockReadOnly
csql = "SELECT ORD_REF,PART,DES,QTY,VALUE from savedORDER where ORD_REF = '54'"
CrystalReport1.Connect = App.Path & "\xy.mdb"
CrystalReport1.ReportFileName = "D:\indigo stationwagon\proj\crbyval.rpt"
CrystalReport1.WindowLeft = 0
CrystalReport1.WindowState = crptMaximized
CrystalReport1.SQLQuery = (csql)
CrystalReport1.Destination = crptToWindow
CrystalReport1.Action = 1

End Sub

Kindly tell me as soon as possible. its very urgent.

10-12-2004, 07:59 PM
What error do you receive? And is ORD_REF a numerical field or a string data type? Remove the ()'s around the csql variable as well. Also, put brackets, [], around value since this is a reserved word.

10-12-2004, 11:16 PM
don't get any error message. but instead of showing the selected record it just shows all the records.
Any suggestions?

10-15-2004, 09:22 PM
Did you remove the () from around your declaration:

CrystalReport1.SQLQuery = csql

And again, what is the assigned data type of the ORD_REF field, is it a string, numerical, etc.

If you simply run this query in the Access query designer, how many records are returned?

Since you are also using old OCX technology, I believe you should also add .ReadRecords after your .sqlquery declaration.

And what is the purpose of this ADO code piece:

rs.Open "SELECT ORD_REF,Part,Des,Qty,VALUE FROM savedORDER WHERE ORD_REF = '54'", conn, adOpenStatic, adLockReadOnly

You are not using this ADO object anywhere..it has no direct relation to your report object, the sqlquery method and .connect method are completely independant of this call and this has no effect on your report in its current state.

And you would probably get better results using the .DataFiles(0) method instead of the .connect method for an OLE DB Access data source. Then, use the .LogonServer method to actually connect the report to the database.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum