-
Nov 1st, 2005, 11:12 PM
#1
Thread Starter
New Member
How to call crystal reports 8.5 from vb 6.0
Hi there,
Can anyone help me out,
I am using crystal reports 8.5 and visual basic 6.0
I created a report and want to call it using vb6.0 and then show it
?How can i do this??
PS: I tried using crviewer but could not get anything (when i run, either the form is blank and gets hanged up)
Thanks very much in advance
I am attaching the code I used :
VB Code:
Dim CRXApplication As CRAXDDRT20.Application
Dim CRXReport As CRAXDDRT20.report
Dim CRXDatabase As CRAXDDRT20.Database
Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
Me.WindowState = 2 'Maximized
Set db = New ADODB.Connection
cnn = "driver=sql server;server=my_server;database=mytest;uid=my_uid;pwd=my_pwd"
db.Open cnn
Set rs = New ADODB.Recordset
rs.Open "select distinct deptic,name,attdic from view_icnotequal where year(attd_date)='2005' and month(attd_date)='09' and dept_id=13", db, adOpenStatic, adLockReadOnly
Set CRXApplication = New CRAXDDRT20.Application
Set CRXReport = New CRAXDDRT20.report
Set CRXDatabase = CRXReport.Database
Set CRXReport = CRXApplication.OpenReport("d:\sarada\testreport1.rpt", 1)
CRXReport.DiscardSavedData
CRXReport.Database.Tables(1).SetDataSource rs, 3
CRViewer.ReportSource = CRXReport
CRViewer.ViewReport
'*// Clean up
Set CRXDatabase = Nothing
Set CRXReport = Nothing
Set CRXApplication = Nothing
End Sub
Private Sub Form_Resize()
CRViewer.Top = 0
CRViewer.Left = 0
CRViewer.Height = ScaleHeight
CRViewer.Width = ScaleWidth
End Sub
Private Sub Form_Terminate()
'*// Clean up
Set CRXDatabase = Nothing
Set CRXReport = Nothing
Set CRXApplication = Nothing
End Sub
thanks very much
Regards
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
Last edited by Hack; Nov 2nd, 2005 at 06:30 AM.
-
Nov 2nd, 2005, 01:26 AM
#2
Re: How to call crystal reports 8.5 from vb 6.0
You don't appear to be using this reference, Dim CRXDatabase As CRAXDDRT20.Database so you may as well get rid of it. Have you tried this
VB Code:
CRXReport.Database.Tables([color=red][b]0[/b][/color]).SetDataSource rs, 3
In VB.Net this starts at zero, don't know whether it's the same for VB6, but it's worth a shot.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Nov 2nd, 2005, 02:01 AM
#3
Thread Starter
New Member
Re: How to call crystal reports 8.5 from vb 6.0
Hi
Thanks for your help..
but unfortunately, it did not work, when ever i try to add 0 to
CRXReport.Database.Tables(1).SetDataSource rs, 3
then it is saying subscript out of range.
Any more ideas??
Thanks any way..
-
Nov 2nd, 2005, 04:25 PM
#4
Re: How to call crystal reports 8.5 from vb 6.0
This code works for me. This is Crystal 9 but it it should work similarly for 8.5, you'll just need to change the references form CRAXDRT to CRAXDRT20.
VB Code:
Option Explicit
Private crApp As CRAXDRT.Application
Private crReport As CRAXDRT.Report
Private Const Provider As String = "Microsoft.Jet.OLEDB.4.0"
Private cn As ADODB.Connection
Private rs As ADODB.Recordset
Private Sub cmdPrint_Click()
Dim sql As String
Set rs = New ADODB.Recordset
sql = "SELECT [Field1], [Field2], [Field3] "
sql = sql & "From [MyTable] "
sql = sql & "WHERE [MyField] = '" & SomeValue & "'"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
Set crApp = New CRAXDRT.Application
Set crReport = crApp.OpenReport("MyReport.rpt")
crReport.Database.Tables(1).SetDataSource rs
CRViewer.ReportSource = crReport
CRViewer.ViewReport
rs.Close
Set rs = Nothing
Set crReport = Nothing
Set crApp = Nothing
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open "Provider=" & Provider & ";Data Source=MyDb.mdb"
End Sub
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Jul 9th, 2008, 08:28 PM
#5
New Member
Re: How to call crystal reports 8.5 from vb 6.0
I have seen your sample but when type the code below it can not work. what anything should I add in referent because declare it can not show the class CRAXDDRT20.report. what can I do??? Thank In Advance.
-
Jul 9th, 2008, 11:04 PM
#6
Re: How to call crystal reports 8.5 from vb 6.0
Try :
Code:
CRXReport.DiscardSavedData
CRXReport.Database.SetDataSource rs
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|