Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recordset as datasource of Crystal Report

Status
Not open for further replies.

leangross

IS-IT--Management
Jul 3, 2002
84
PH
Im using Crystal report 8 and VB6, my problem is how can i make the Crystal report get the record from the recordset i made. The problem is when i run the report it shows all the record from the table. How can i make the report show only the content of the recordset?



Below is the code im using. dcCategory is datacombo.

Code:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.Open "File name=c:\Product.udl"
Set rst = cnn.Execute("select item_no,item_category,Item_desc,Item_unit,item_price from tblitems where item_Category ='" & dcCAtegory.Text & "'")

Dim crystal As CRAXDRT.Application 
Dim treport As CRAXDRT.Report     
    
CRViewer1.DisplayBorder = False  
CRViewer1.DisplayTabs = False    
CRViewer1.EnableDrillDown = False
CRViewer1.EnableRefreshButton = False


Dim crxApplication As New CRAXDRT.Application
Set crystal = New CRAXDRT.Application
Set treport = crystal.OpenReport("d:\application\list.rpt")

treport.DiscardSavedData       
treport.Database.SetDataSource rst 
   
CRViewer1.ReportSource = treport
CRViewer1.ViewReport

When i design the report using crystal report designer i use the table as the datasource and i did not set anything else. Could this be the problem?

Thanks in advance!!!
 
yes I know for the vb6 datareport you have to make the recordsource for the report the same one as the criteria for a recordset that would only return the one record you want. This is useful because you only need one form for many different queries with different names to the columns set by Section(2).label(N).Caption=MyRec.Fields(N).name

I saw a reference recently to using parameters for Crystal reports in which case you just use the table and feed combo box into the parameter value. I cant remember exactly how but search for parameter crystal reports vb6
 
You can set up your report to use active data instead of going to a database. You will need to create a .ttx file for the report and then pass the report your recordset. See the following article,


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
I think you have to down another level. At the moment you are using the setdatasource on the database.
Get a reference to the tables collection and loop around that, then use the setdatasource on the tables instead.

Regards,

Patrick
 
This works for me.

Dim rs As ADODB.Recordset

'sFilename set previously as well as the sSql (query)

Set CrxApp = New CRAXDRT.Application
Set CrxRpt = CrxApp.OpenReport(sFileName)
Set rs = New ADODB.Recordset

rs.Open sSql, cConn, adOpenForwardOnly, adLockReadOnly

CrxRpt.RecordSelectionFormula = ""

CrxRpt.Database.Tables(1).SetLogOnInfo sServer, sDataBase, sLoginUser, sPassword

CrxRpt.DiscardSavedData
CrxRpt.Database.SetDataSource rs

crvReport.ReportSource = CrxRpt

crvReport.ViewReport


Very nice site . . .


I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top