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

Problem with subreport

Status
Not open for further replies.

capelle

Programmer
May 22, 2001
2
0
0
NL
Hi all,


I have Crystal Reports version 8.0.1.0
I use the CRViewer that allows me to connect my Visual Basic 6 Application with reports that are generated with Crystal Reports. The connection is a native connection with MS ACCESS 2000.

My problem is to connect my database to a subreport.
To connect to my report i use the code in VB6.0

--------start code---------------------

Dim appn As New CRAXDRT.Application
Dim CRXReport As New CRAXDRT.Report
Dim CRXDatabase As CRAXDRT.Database
Dim CRXTable As CRAXDRT.DatabaseTable
Dim CRXTables As CRAXDRT.DatabaseTables
Dim CRXParams As CRAXDRT.ParameterFieldDefinition

On Error GoTo rapportdefinitie_error

Set CRXReport = appn.OpenReport(dbSettings.rapportpad & "\" & Cr_rapportlok)

Set CRXTables = CRXReport.Database.Tables
Set CRXTable = CRXTables.Item(1)

If Cr_SelectQuery <> &quot;&quot; Then
CRXReport.ParameterFields(1).AddCurrentValue (Cr_SelectQuery)
Else
CRXReport.ParameterFields(1).AddCurrentValue (&quot;&quot;)
End If

CRXTable.Location = dbSettings.path

etc.

--------------------- end code -------------------

My database is not in the same directory as the report-files. The question is: How can i set the databaselocation for the subreport in VB code??

Thanks in advance...
 
I suppose u need to create separate database and table objects for the subreport also.Have a separate report object for the subreport also.
Try the following

'add these declarations
Dim CRXSubReport As New CRAXDRT.Report
Dim CRXSubDatabase As CRAXDRT.Database
Dim CRXSubTable As CRAXDRT.DatabaseTable
Dim CRXsubTables As CRAXDRT.DatabaseTables
Dim CRXSubParams As CRAXDRT.ParameterFieldDefinition

'this is to set the database for the subreport
set CRXSubReport=CRXReport.open Subreport(&quot;subreportname&quot;)
Set CRXSubTables = CRXSubReport.Database.Tables
Set CRXSubTable = CRXSubTables.Item(1)


Try this ,iam not sure just putting an idea :)

 
Your database need not be in the same directory as the report-files.
The code below sets the Database location for Main report and Sub report. It looks for all the sub report in the main
report and set's the new location.

---------------Check this code----------------------

Dim Report As CRAXDRT.Report
Dim CRXParamDefs As CRAXDRT.ParameterFieldDefinitions
Dim CRXParamDef As CRAXDRT.ParameterFieldDefinition
Dim Application As New CRAXDRT.Application
Dim sReportObjects As CRAXDRT.ReportObjects
Dim subReport As CRAXDRT.Report
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim ReportObject As Object
Dim crxReportObjects As CRAXDRT.ReportObjects
Dim sReport As CRAXDRT.SubreportObject

Set Report = Application.OpenReport(MainReportName)
Report.Database.SetDataSource MdbDataPath & &quot;MdbFile.mdb&quot;
For i = 1 To Report.Database.Tables.Count
Report.Database.Tables(i).Location = MdbDataPath & &quot;MdbFile.mdb&quot; '
Next i
Report.DiscardSavedData 'Discard old data
Set subReport = Report
Set crxSections = subReport.Sections
For Each crxSection In crxSections
Set crxReportObjects = crxSection.ReportObjects
For Each ReportObject In crxReportObjects
If ReportObject.Kind = crSubreportObject Then
Set sReport = ReportObject
Set subReport = sReport.OpenSubreport
For i = 1 To subReport.Database.Tables.Count
subReport.Database.Tables(i).Location = MdbDataPath & &quot;MDBFile.mdb&quot;
Next
End If
Next
Next
CRViewer1.ReportSource = Report
CRViewer1.ViewReport

'-----------end---------------------
Hope this helps..Thanks Murali

Murali Bala
 
Thanks for the answer. It helped!!

I've another problem with a native connection that's making me crazy. I want to connect my CR-Viewer (VB6) with a ACCESS 2000 Database that has a database-password. I cannot find an answer on the seagatesoftware-site for my problem.
Anybody knows how to handle this?

Thanks in advance.
 
hi:
Try to connect to the databse in this way..should work..
-----------------------------start---------------
Dim strcnn As String
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection

cnn.ConnectionString = &quot;ODBC;DBQ=&quot; & &quot;c:\MdbFile.mdb&quot; & &quot;;UID = Admin ;PWD=mypass;Driver={Microsoft Access Driver (*.mdb)}&quot;
cnn.open
Set rs = New ADODB.Recordset
strcnn = &quot;SELECT * FROM TableName&quot;
rs.open strcnn, cnn, adOpenDynamic, adLockOptimistic
-----------end------------------- Murali Bala
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top