SelectionFormula or SQLQueryString??

gchwee
04-14-2004, 12:15 PM
Hi, How to pass the data range from vb6.0 to crystal report9.0?
Someone told me that i should use Selection formula, Someone told me that i should use the SQLQueryString to pass it. I did try both of them, But i fail...
what i try as below:

Public Report1 As New CRAXDRT.Report
Private Sub Form_Load()
Dim crxApp As New CRAXDRT.Application
dim a as String
Screen.MousePointer = vbHourglass
Set Report1 = crxApp.OpenReport("C:\Repor1.rpt")
crxreport.SQLQueryString = "SELECT name, address FROM Table1 WHERE name = "&a""
CRViewer91.ReportSource = crxreport
CRViewer91.ViewReport
CRViewer91.Zoom 94
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidth
End Sub[/COLOR]
'ERROR


====================
Ok, nvm, So... i try SelectionFormula from other forum discuss.

Private Sub Form_Load()

Dim crxApp As New CRAXDRT.Application
Dim report1 As New CRAXDRT.Report
Screen.MousePointer = vbHourglass
Dim a As String
Set report1 = crxApp.OpenReport("c:\Report1.rpt")
a = Form2.Text1.Text
report1.RecordSelectionFormula = "{Table1.name} = ' " & a & " ' "
CRViewer91.ReportSource = report1
report1.DiscardSavedData
CRViewer91.ViewReport
CRViewer91.Zoom 94
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidth
End Sub

ERROR: 'null Report show. How come?

Why the command below is not recognise by my vb6.0? izit bcos i forget to declare of it?
CRP1.DataFiles(0) = DataSource
CRP1.ReportFileName = App.Path & "\Reports\" & FileName
CRP1.WindowTitle = title
CRP1.Destination = Destination
CRP1.WindowState = crptMaximized
CRP1.Action = crptToWindow

I already create a beautiful design and full record crystal report, i just wish to use vb to activate/pass parameter to the cystalreport's SELECTIONEXPERT to generate seperate account of report, can i?

Thanks~

MKoslof
04-14-2004, 03:14 PM
You can use the SQLQueryString method, do you need to watch your query declaration. Name is a reserved word, so you need []'s around it. And, you need to pass in the string variable correctly, see below:



Dim sSQL as string

sSQL = "SELECT [Name], address FROM Table1 WHERE [Name] = '" & Form2.Text1.Text & "'"

crxreport.discardsavedData
crxreport.SQLQueryString = sSQL



You could use the recordselectionformula method too..that is actually my preferred method...use the same type of procedure



Dim sSQL as string

sSQL = "{Table1.name} = ' " & a & " ' "

crxReport.discardsavedData
crxReport.recordselectionFormula = sSQL



You call DiscardSaved data BEFORE attempting to assign a new recordset

And, you have mixed up methods here. You are using the CRAXDRT object library which means you need to use the RDC and the Active Data Driver. Go to your report and change your datasource to the Active Data Driver. Then, you don't need the DataFiles(0) method. You should be using the .SetlogonInfo and .LogonServer methods to connect your report to the database. Or, if using an Access mdb file, you can use .Connect in place of .SetLogonInfo for your tables.

And, instead of using the SQLQueryString method, since you want to use the RDC and the CRAXDRT methods, you want to use the SetDataSource method to pass the report a recordset object. You would open a standard ADO connection and recordset.

gchwee
04-14-2004, 04:41 PM
Well, MKoslof. Hi :)
Correct me if i am wrong :)

So... what i do is ...

1st changePrivate Sub Form_Load()
Dim crxApp As New CRAXDRT.Application
Dim report1 As New CRAXDRT.Report
Screen.MousePointer = vbHourglass
Dim a As String
Dim sql As String
Set report1 = crxApp.OpenReport("c:\Report1.rpt")
a = "gohcheokwee"
sql = "{Table1.name} = ' " & a & " ' "
report1.DiscardSavedData '<----Change
report1.RecordSelectionFormula = sql
CRViewer91.ReportSource = report1
CRViewer91.ViewReport
CRViewer91.Zoom 94
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidth
End Sub


2nd change
go crystal report:
"Database"-->"Set Datasource Location"-->"OLE DB (ADO)"
Change the report database location to ADO, right?

But... i still get a null report.

MKoslof
04-14-2004, 05:53 PM
Looks like you are almost there. I would dump the extra variable and just go with one string declaration. And now that you are using ADO, your table is probably automatically aliased. Meaning, this might be your actual string:



Dim sSQL as string

sSQL = "({Ado.Name} = 'gohcheokwee')"

crxReport.discardsavedData
crxReport.RecordSelectionFormula = sSQL



What database type are you using, this is Access, correct?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum