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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report Error

Status
Not open for further replies.

ferozy

Programmer
Feb 25, 2003
20
FJ
Hi,

My code below opens Crystal report but the report is empty, there are no fields showing,
what am doing wrong. This is the First time I am using crystal reports in VB, so Iam quite
confused.

Can anybody please help me.

Thanks.


Private Sub cmdReport_Click()
'frmReport.Show
Dim cnn As cls_Sys_DB, rst As ADODB.Recordset
Dim Report As CrystalReport1
Set cnn = New cls_Sys_DB
Set rst = New ADODB.Recordset
Set Report = New CrystalReport1

''Set SQL to load and generate reports
cnn.Query = "SELECT EmployeeDetails.EmpID, EmployeeDetails.FirstName, EmployeeDetails.Surname, EmployeeDetails.Reports_To " & _
"FROM EmployeeDetails"
cnn.Execute False, rst

Report.Database.SetDataSource rst
Form2.CRViewer1.ReportSource = Report
Form2.CRViewer1.ViewReport
Form2.Show
 
Report.Database.SetDataSource rst
Form2.CRViewer1.ReportSource = Report
Form2.CRViewer1.DiscardSavedData '<---Add this line
Form2.CRViewer1.ViewReport
Form2.Show
 
Hi,

I tried and my program crashed 3 times.

Anyway if I dont add that line and run it as before the report opens (Form2), its blank
and at the top the pages show 0 of 0+ and when I click next page it shows me the report with
the fields I had created.
So what am I doing wrong.

I am new to crystal report and its use, can some one please tell me or give me an example
how I can use crystal report in my project.

My project has a DSN connection to Microsoft Access database, how can I design, and
write sql in visual basic to get the data and display the report.
What do I have to do.

I will appreciate your help on this.

Thanks.
 
ferozy,

Here's some code I use in a VB6 app for opening a report (I used the same code for Crystal 7.0 and 8.5). This is using SQL Server, so there will be some changes needed for Access. There might be more info on CrystalDecisions.com website.

The calling form has a Crystal Report object, and the form being called that its viewed on has a Crystal Report Viewer Object. I included all the References and Components that looked like they were needed for Crystal....

Dim crxApp As New CRAXDRT.Application
Dim crxRep As New CRAXDRT.Report
Dim frmViewerForm As frmReports2 ' your form with CRviewer control

' create instance of Form2 that has CRViewer
Set frmViewerForm = New frmReports2
' connect to db (you could probably leave out the first parameter for Access, just start w/ the DSN name!!!!)
crxApp.LogOnServer &quot;p2sodbc.dll&quot;, &quot;DSNName&quot;, &quot;DatabaseName&quot;, &quot;username&quot;, &quot;password&quot;


' open the report
Set crxRep = crxApp.OpenReport(fileName)

' point the viewer to the report
frmViewerForm.CRViewer1.ReportSource = crxRep
' show the form / report

frmViewerForm.CRViewer1.viewReport
frmViewerForm.Show

Hopefully this is helpful....
Ray
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top