Can anybody tell me where should i pass sql statement in crystal
report . suppose i want to pass these codes in crystal report.this
would be greately appereciated.

RECORDSQL = "SELECT * From MR WHERE (((MR.Req_no)=" & Text12.Text & "));"
   rs.Open RECORDSQL, con, adOpenDynamic, adLockOptimistic

Hi, from your code, you are getting a value to include in the query from a TextBox. The Textbox clearly cannot be seen by Crystal Reports. That means you'll need to compose that query to be complete in Vb before passing it to CR.
CR has dlls to help you pass queries and/or parameters to it before display. I don't have sufficient information on the dlls, but I know that's the way to go about it, not straight code to CR.
Regards.

i have written a code can you give any suggestion:

Dim crystal As CRAXDDRT.Application
Dim Report As CRAXDDRT.Report
Dim cparam As CRAXDDRT.ParameterFieldDefinition
Dim cparams As CRAXDDRT.ParameterFieldDefinitions
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim recordsql As String

Private Sub Form_Load()
Call loadreport
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Zoom 100
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub
Private Sub loadreport()
Set con = New Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
Set rs = New ADODB.Recordset
Set crystal = New CRAXDDRT.Application
Set Report = New CRAXDDRT.Report
recordsql = "SELECT * From MR WHERE (((MR.Req_no)=" & MR.Text12 & "))"
rs.Open recordsql, con, adOpenDynamic, adLockOptimistic
MsgBox (MR.Text12)
Set Report = crystal.OpenReport(App.Path & "\" & "list2.rpt", 0)
Report.RecordSelectionFormula = recordsql
End Sub

Instead of RecordSelectionFormula, try this:
Report.SQLQueryString = recordsql. Plus, I don't see where you have logged in with your crystal variable(crystal.LogOnServer).

Can you tell me how should i log in with crystal variable crystal.LogOnServer). ?
i have written a code :

Dim crystal As CRAXDDRT.Application
Dim Report As CRAXDDRT.Report
Dim cparam As CRAXDDRT.ParameterFieldDefinition
Dim cparams As CRAXDDRT.ParameterFieldDefinitions
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim recordsql As String

Private Sub CRViewer1_CloseButtonClicked(UseDefault As Boolean)

End Sub

Private Sub Form_Load()
Call loadreport
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Zoom 100
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub
Private Sub loadreport()
Set con = New Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
Set rs = New ADODB.Recordset
Set crystal = New CRAXDDRT.Application
Set Report = New CRAXDDRT.Report
recordsql = "SELECT * From MR WHERE (((MR.Req_no)=" & MR.Text12 & "))"
rs.Open recordsql, con, adOpenDynamic, adLockOptimistic
MsgBox (MR.Text12)
Set Report = crystal.OpenReport(App.Path & "\" & "list2.rpt", 0)
'Report.RecordSelectionFormula = recordsql
Report.SQLQueryString = recordsql
End Sub
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.