bawasi
asked on
Urgent!! Package and Deployment of VB6 project with Crystal report
Hello. I created an installer of my VB6 project with crystal report on it. After installing it to other computer (not my computer where I developed it), I get an error "Physical database not found, logonserver errors,file not found" and so on. Actually I already encounter this kind of error, and I already fix it, but now I dont know why is this happening again. I fix this before when I dont have any subreport on my crystal report, and I think there something to do with my database path in my subreports.
In my VB6 project, I had a crystal report on it, I created my main report in vb6 and not in crystal report, but my subreports, I created them in crystal report and use Visual basic to add subreport to my project.
And during my package and deployment, I did include those .rpt(which I use in my subreport). And still there has a problem.
I also use this code inside my form where the CRViewer is in place:
Private Sub Form_Load() 'to specify the path of my database to the main report
Set mrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
For i = 1 To crxReport.Database.Tables. count
crxReport.Database.Tables( i).SetLogO nInfo "sql server", "database", "usernm", "password"
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
If printselect = 1 Then
crxReport.RecordSelectionF ormula = "{ado.ItemNo} =" & "'" & (rs!ItemNo) & "'"
Else
crxReport.RecordSelectionF ormula = ""
End If
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
CRViewer1.EnableGroupTree = False
CRViewer1.Zoom 100
While CRViewer1.IsBusy
DoEvents
Wend
End Sub
Please Help. Tnx in advance
In my VB6 project, I had a crystal report on it, I created my main report in vb6 and not in crystal report, but my subreports, I created them in crystal report and use Visual basic to add subreport to my project.
And during my package and deployment, I did include those .rpt(which I use in my subreport). And still there has a problem.
I also use this code inside my form where the CRViewer is in place:
Private Sub Form_Load() 'to specify the path of my database to the main report
Set mrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
For i = 1 To crxReport.Database.Tables.
crxReport.Database.Tables(
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
If printselect = 1 Then
crxReport.RecordSelectionF
Else
crxReport.RecordSelectionF
End If
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
CRViewer1.EnableGroupTree = False
CRViewer1.Zoom 100
While CRViewer1.IsBusy
DoEvents
Wend
End Sub
Please Help. Tnx in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes I understand the code, but how will I change the database path of the subreports? To my main report, I specify the connection string of my database just like this:
Set mrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
For i = 1 To crxReport.Database.Tables. count
crxReport.Database.Tables( i).SetLogO nInfo "sql server", "database", "usernm", "password"
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
How can I do it to the subreports specifying my sql statement and connection strings.
Set mrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
For i = 1 To crxReport.Database.Tables.
crxReport.Database.Tables(
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
How can I do it to the subreports specifying my sql statement and connection strings.
Did you look at the link?
Basic process is this:
Loop through each section of the main report
Loop through each object in the section
If this object is a subreport then
Loop through tables in subreport
Apply setlogoninfo method
End loop
End if
End loop
End loop
Does that help or did I not understand what you're asking?
frodoman
Basic process is this:
Loop through each section of the main report
Loop through each object in the section
If this object is a subreport then
Loop through tables in subreport
Apply setlogoninfo method
End loop
End if
End loop
End loop
Does that help or did I not understand what you're asking?
frodoman
ASKER
This is now my new Form_Load:
Private Sub Form_Load()
Dim Report As New CrystalReport1
Dim crxTables As CRAXDRT.DatabaseTables
Dim crxTable As CRAXDRT.DatabaseTable
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim crxSubreportObj As CRAXDRT.SubreportObject
Dim crxReportObjects As CRAXDRT.ReportObjects
Dim crxSubreport As CRAXDRT.Report
Dim ReportObject As Object
Form3.Left = 0
Form3.Top = 0
Form3.WindowState = 2
Set mrs = New ADODB.Recordset
Set Hrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
hsql = "Select * from PicOtherHeadTbl" 'I add this for the path of subreport
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
Hrs.Open hsql, cn, adOpenStatic, adLockOptimistic 'I add this for the path of subreport
For i = 1 To crxReport.Database.Tables. count
crxReport.Database.Tables( i).SetLogO nInfo "sql server", "database", "usernm", "password"
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
Set crxSections = Report.Sections
For Each crxSection In crxSections
Set crxReportObjects = crxSection.ReportObjects
For Each ReportObject In crxReportObjects
If ReportObject.Kind = crSubreportObject Then
Set crxSubreportObj = ReportObject
Set crxSubreport = crxSubreportObj.OpenSubrep ort
crxSubreport.Database.Tabl es(1).SetL ogOnInfo "sql server", "database", "usernm", "password"
crxSubreport.DiscardSavedD ata 'this doesn't work
crxSubreport.Database.SetD ataSource Hrs 'this doesn't work
End If
Next ReportObject
Next crxSection
If printselect = 1 Then
crxReport.RecordSelectionF ormula = "{ado.ItemNo} =" & "'" & (rs!ItemNo) & "'"
Else
crxReport.RecordSelectionF ormula = ""
End If
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
CRViewer1.EnableGroupTree = False
CRViewer1.Zoom 100
While CRViewer1.IsBusy
DoEvents
Wend
End Sub
I can't seem to change the datasource of the Subreport. I even try to copy the whole file of my vb project and paste to a temporary folder for trial and error: Example:
Original path:
C:\VbProject\Version1
Database path
C:\VBproject\Version1\db.m db
New Path:
C:\VbProject\Version2
Database path
C:\VBproject\Version2\db.m db
but it was funny that my subreport database path is reading the database at "C:\VBproject\Version1\db. mdb" and not the "C:\VBproject\Version2\db. mdb".
Thats why I want to specify the dbase path of the subreports during runtime.
Private Sub Form_Load()
Dim Report As New CrystalReport1
Dim crxTables As CRAXDRT.DatabaseTables
Dim crxTable As CRAXDRT.DatabaseTable
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim crxSubreportObj As CRAXDRT.SubreportObject
Dim crxReportObjects As CRAXDRT.ReportObjects
Dim crxSubreport As CRAXDRT.Report
Dim ReportObject As Object
Form3.Left = 0
Form3.Top = 0
Form3.WindowState = 2
Set mrs = New ADODB.Recordset
Set Hrs = New ADODB.Recordset
sql = "Select * from Table1 ORDER BY ItemNo"
hsql = "Select * from PicOtherHeadTbl" 'I add this for the path of subreport
mrs.Open sql, cn, adOpenStatic, adLockOptimistic
Hrs.Open hsql, cn, adOpenStatic, adLockOptimistic 'I add this for the path of subreport
For i = 1 To crxReport.Database.Tables.
crxReport.Database.Tables(
Next
With crxReport
.DiscardSavedData
.Database.SetDataSource mrs
End With
Set crxSections = Report.Sections
For Each crxSection In crxSections
Set crxReportObjects = crxSection.ReportObjects
For Each ReportObject In crxReportObjects
If ReportObject.Kind = crSubreportObject Then
Set crxSubreportObj = ReportObject
Set crxSubreport = crxSubreportObj.OpenSubrep
crxSubreport.Database.Tabl
crxSubreport.DiscardSavedD
crxSubreport.Database.SetD
End If
Next ReportObject
Next crxSection
If printselect = 1 Then
crxReport.RecordSelectionF
Else
crxReport.RecordSelectionF
End If
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
CRViewer1.EnableGroupTree = False
CRViewer1.Zoom 100
While CRViewer1.IsBusy
DoEvents
Wend
End Sub
I can't seem to change the datasource of the Subreport. I even try to copy the whole file of my vb project and paste to a temporary folder for trial and error: Example:
Original path:
C:\VbProject\Version1
Database path
C:\VBproject\Version1\db.m
New Path:
C:\VbProject\Version2
Database path
C:\VBproject\Version2\db.m
but it was funny that my subreport database path is reading the database at "C:\VBproject\Version1\db.
Thats why I want to specify the dbase path of the subreports during runtime.
crxSubreport.DiscardSavedD ata 'this doesn't work
crxSubreport.Database.SetD ataSource Hrs 'this doesn't work
As far as I know you don't need these lines of code at all - subreport shouldn't require the discard method.
Also you may want to change this:
crxSubreport.Database.Tabl es(1).SetL ogOnInfo "sql server", "database", "usernm", "password"
To this:
For i = 1 To crxSubeport.Database.Table s.count
crxSubReport.Database.Tabl es(i).SetL ogOnInfo "sql server", "database", "usernm", "password"
Next
This will make sure you get all of the tables if there are multiples.
Hopefully that'll do it for you. I'm going to be offline for the most of the remainder of today but I'll check back tonight or tomorrow if you still need help.
frodoman
crxSubreport.Database.SetD
As far as I know you don't need these lines of code at all - subreport shouldn't require the discard method.
Also you may want to change this:
crxSubreport.Database.Tabl
To this:
For i = 1 To crxSubeport.Database.Table
crxSubReport.Database.Tabl
Next
This will make sure you get all of the tables if there are multiples.
Hopefully that'll do it for you. I'm going to be offline for the most of the remainder of today but I'll check back tonight or tomorrow if you still need help.
frodoman
ASKER
I finally got it frodoman. I change this line
Set crxSections = Report.Sections
to this line -> Set crxSections = crxReport.Sections
crxReport is my main "New CrystalReport1"
and also I added this code:
crxSubreport.Database.SetD ataSource Hrs
to change the database path of Subreports.
Thanks again for your help.
Set crxSections = Report.Sections
to this line -> Set crxSections = crxReport.Sections
crxReport is my main "New CrystalReport1"
and also I added this code:
crxSubreport.Database.SetD
to change the database path of Subreports.
Thanks again for your help.
Glad to help - frodoman
ASKER