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

Crystal Report Designer Path at Run Time

Status
Not open for further replies.

HVehari

Technical User
Sep 4, 2003
42
SA
Hi,
WE designed a report by Crystal report designer.
We like to assign different path for the Database at run time. Any help will be appriciated

With best regards,

Shafeeq
 
This resets the paths in a report and sub-reports (if any)
Code:
Public Sub FormatCrystalReport( _
       Rep_Path As String, _
       Rep_Name As String, _
       Data_Path As String, _
       Report_Title As String)


    Dim rdApp               As CRAXDRT.Application
    Dim rpt                 As CRAXDRT.Report
    Dim tbl                 As CRAXDRT.DatabaseTable
    Dim SubReportObj        As CRAXDRT.SubreportObject
    Dim SubReport           As CRAXDRT.Report
    Dim Section             As CRAXDRT.Section
    Dim RObject             As Object
            
    Set rdApp = CreateObject("CrystalRuntime.Application")
    Set rpt = rdApp.OpenReport(Rep_Path & Rep_Name)
Code:
' Reset the database paths in subReports
Code:
    For Each Section In rpt.Sections
        For Each RObject In Section.ReportObjects
            If RObject.Kind = crSubreportObject Then
                Set SubReportObj = RObject
                Set SubReport = SubReportObj.OpenSubreport
                For Each tbl In SubReport.Database.Tables
Code:
' Direct Access Database
Code:
                    tbl.Location = Data_Path & Mid$(tbl.Location, _
                          InStrRev(tbl.Location, "\") + 1)
                Next tbl
            End If
        Next RObject
    Next Section
    Set SubReportObj = Nothing
    Set SubReport = Nothing
Code:
' Reset the data paths for all the databases in the report.
Code:
    For Each tbl In rpt.Database.Tables
        tbl.Location = Data_Path & Mid$(tbl.Location, _
                       InStrRev(tbl.Location, "\") + 1)
    Next
End Sub
You need to do something a bit more elaborate if you are accessing the databases with ODBC.
 
What would you have to do accessing a database with ODBC?
 
Think you need to use the SetLogOnInfo method. This typically works for me:
Code:
    For Each tbl In rpt.Database.Tables
        tbl.Location = tbl.Name
        tbl.SetLogOnInfo <ODBC_DSN>, <databasename>, <userid>, <password>
    Next
-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top