-
Jun 8th, 2014, 05:53 AM
#1
Thread Starter
Lively Member
[RESOLVED] VB 6 And Crystal Report 8.5
Hello All,
I'm using this codes to connect CR
Code:
Private sub Command2.Click()
Dim crxTable As CRAXDRT.DatabaseTable
Dim mReport As CRAXDRT.Report
For Each crxTable In mReport.Database.Tables
crxTable.SetLogOnInfo "ODBCDATA", "Data.mdb", "admin", ""
DoEvents
Next
End sub
But i always met with the error "OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET" (Highlighted line)
How to face with the error and any other options to connect database with ODBC
( I Already connected CR 8.5 with access with ole db. I installed my program on another computer. But crystal report
did't search access file in application installed folder.. so i searched in google and crystal report forums everyone said
to connect it with odbc.. So i do it.. But the error was blocking me..)
How can i do this..
Please Help.
Thanks to spend your time with my question..
Thank You
-
Jun 9th, 2014, 01:46 PM
#2
Re: VB 6 And Crystal Report 8.5
Thread moved from the 'VB6 and Earlier' forum to the 'Reporting' forum
-
Jun 9th, 2014, 09:51 PM
#3
Thread Starter
Lively Member
Re: VB 6 And Crystal Report 8.5
-
Jun 10th, 2014, 12:40 PM
#4
Re: VB 6 And Crystal Report 8.5
Never used cr in VB6, only vb .Net. But it seem like you would to change this,
Code:
Dim mReport As CRAXDRT.Report
to
Code:
Dim mReport As NEW CRAXDRT.Report
Also, you haven't loaded a report to "mReport", so the "For Loop" seems pointless.
-
Jun 11th, 2014, 06:45 AM
#5
Addicted Member
Re: VB 6 And Crystal Report 8.5
Originally Posted by wes4dbt
Code:
Dim mReport As NEW CRAXDRT.Report
Do you mean this?
Code:
Set mReport = NEW CRAXDRT.Report
Computer Enterprise Masoud Keshavarz
For more information contact masoudk1990@yahoo.com
-
Jun 11th, 2014, 07:08 AM
#6
Addicted Member
Re: VB 6 And Crystal Report 8.5
From here http://www.mahipalreddy.com/cr/article52645.htm
Something like this should work:
Code:
'Add a command button and a Crystal Report Viewer Control to you form
'Reference Crystal Reports 8/8.5/9/10 ActiveX Designer Run time Library
'Paste the following code into the form code window
'Change the path "C:\crtests\Report1.rpt" to suit yours
Private Sub Command1_Click()
Dim CrxApp As CRAXDRT.Application
Dim CrxRep As CRAXDRT.Report
Dim crxDatabase As CRAXDRT.Database
Dim crxDatabaseTables As CRAXDRT.DatabaseTables
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
Set CrxApp = New CRAXDRT.Application
Set CrxRep = CrxApp.OpenReport("H:\test\crtests\Report1.rpt")
'Set your Database object to the Report object's Database object
Set crxDatabase = CrxRep.Database
'Set your DatabaseTables object to the Database object's Tables object
Set crxDatabaseTables = crxDatabase.Tables
'Loop through each DatabaseTable object in the DatabaseTables collection and then set the location
'of the database file for each table
For Each crxDatabaseTable In crxDatabaseTables
'If you are using physical path of the access database file (Native connection to PC database)
crxDatabaseTable.Location = App.Path & "\xtremelite.mdb"
'Use next line, if you are using Native connection to SQL database
'crxDatabaseTable.SetLogOnInfo "servername", "databasename", "userid", "password"
'Use next line, if you are using ODBC connection to a PC or SQL database
'crxDatabaseTable.SetLogOnInfo "ODBC_DSN", "databasename", "userid", "password"
Next crxDatabaseTable
CRViewer91.ReportSource = CrxRep
CRViewer91.ViewReport
Set crxDatabase = Nothing
Set crxDatabaseTable = Nothing
Set crxDatabaseTables = Nothing
Set crxReport = Nothing
Set crxApplication = Nothing
End Sub
Computer Enterprise Masoud Keshavarz
For more information contact masoudk1990@yahoo.com
-
Jun 11th, 2014, 11:15 AM
#7
Re: VB 6 And Crystal Report 8.5
Do you mean this?
Code:
Set mReport = NEW CRAXDRT.Report
No, I use the method in my post to create many objects. But, I've never tried it with CR. Have you?
-
Jun 11th, 2014, 10:23 PM
#8
Thread Starter
Lively Member
Re: VB 6 And Crystal Report 8.5
Thanks guys,
masoudk1990 Thanks.. It works..But i need to use the crystal report control. not crystal report viewer..
wes4dbt thanks.. but i got another error in the same line ... the error was "Method 'Database' of object 'IReport' Failed."
How can i face the error.
Thank you..
-
Jun 12th, 2014, 02:31 AM
#9
Addicted Member
Re: VB 6 And Crystal Report 8.5
No, I use the method in my post to create many objects. But, I've never tried it with CR. Have you?
sorry wes4dbt it was my fault.
kamalkumar2023, as wes4dbt said earlier you havent set "mReport".
You must have something like this in your code before foreach loop:
Code:
Set mReport = crxApplication.OpenReport(App.path & "\MyReport.rpt")
Also I can not find this declaration in your click event:
Code:
crxApplication As New CRAXDRT.Application
Is it your full code? Please provide us your full and updated code.
Computer Enterprise Masoud Keshavarz
For more information contact masoudk1990@yahoo.com
-
Jun 12th, 2014, 08:35 AM
#10
Thread Starter
Lively Member
Re: VB 6 And Crystal Report 8.5
Thanks Mr.masoudk
My Question was HOW TO CONNECT ACCESS WITH CRYSTAL REPORT via ODBC with VB 6.
here is my full code
Code:
Private Sub Command4_Click()
Dim crxTable As CRAXDRT.DatabaseTable
Dim mReport As New CRAXDRT.report
Dim crxApplication As New CRAXDRT.Application
Set mReport = crxApplication.openreport("F:\Kamal\New VB Collections\GK LAB\Report\Checking.rpt")
For Each crxTable In mReport.Database.Tables
crxTable.SetLogOnInfo "GK DATA", "Data.mdb", "admin", ""
DoEvents
Next
With CR
.Destination = crptToWindow
.WindowState = crptMaximized
.Action = 1
End With
End Sub
with any changes does this code work for my question ???? or any other ?????
Thank you,
-
Jun 12th, 2014, 10:56 PM
#11
Thread Starter
Lively Member
Re: VB 6 And Crystal Report 8.5
Thanks guys, I GOT IT
Code:
Private Sub Command4_Click()
With CR
.ReportFileName = App.Path & "\Report\Checking.rpt"
.ReplaceSelectionFormula "{R_Patient.regno} =" & Text1.Text & ""
.Connect = "Dsn=GK DATA;Uid=sa;pwd=admin;dsq=database"
.Destination = crptToWindow
.WindowState = crptMaximized
.Action = 1
End With
End Sub
It works..
Thanks Again
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
|