PantoffelSlippers
asked on
Programmatically setting data source location of a Crystal Report to MS Access database
Hi Experts,
I have several Crystal Report XI reports that I automate through VB.Net. These reports point to an Access database. I need to store the path to the access database mdb file as a setting and then set the data source location at run-time with my VB code.
How do I do this?
Thanks
I have several Crystal Report XI reports that I automate through VB.Net. These reports point to an Access database. I need to store the path to the access database mdb file as a setting and then set the data source location at run-time with my VB code.
How do I do this?
Thanks
ASKER
Hi Habibb,
That's not exactly what I was looking for. That example uses VB6 with the CRXDRT DLL which I've used a lot in the past. What I'm trying to do with Access now I can already do with SQL Server, see example below:
Public Sub SetReportConnections(ByRef XReport As ReportDocument)
Dim CInfo As New ConnectionInfo
Dim t As Table
Dim TLogonInfo As TableLogOnInfo
Dim SubR As New ReportDocument
'Set the connection
CInfo.ServerName = ServerName
CInfo.DatabaseName = DatabaseName
CInfo.UserID = UserID
CInfo.Password = Password
'Set Logon details for main report and each table inside the main report
For Each t In XReport.Database.Tables
TLogonInfo = t.LogOnInfo
TLogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TLogonInf o)
Next
For Each SubR In XReport.Subreports
For Each t In SubR.Database.Tables
TLogonInfo = t.LogOnInfo
TLogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TLogonInf o)
Next
Next
End Sub
This procedure explicitly sets the connection details for a report file that connects to SQL Server. Now I need to do exactly the same with MS Access but I'm assuming that different objects / properties / methdos must be used.
From the example in the link I basically need to copy the following logic:
Dim CRXDatabase As CRAXDRT.Database
Set CRXDatabase = CRXReport.Database
CRXDatabase.SetDataSource rs, 3, 1
I'm not using the CRXDRT so this syntax won't work. I can't find the syntax to perform this logic. I need to find the exact syntax for the components that I'm using. I'm using the CrystelDecisions .Net references.
Thanks
That's not exactly what I was looking for. That example uses VB6 with the CRXDRT DLL which I've used a lot in the past. What I'm trying to do with Access now I can already do with SQL Server, see example below:
Public Sub SetReportConnections(ByRef
Dim CInfo As New ConnectionInfo
Dim t As Table
Dim TLogonInfo As TableLogOnInfo
Dim SubR As New ReportDocument
'Set the connection
CInfo.ServerName = ServerName
CInfo.DatabaseName = DatabaseName
CInfo.UserID = UserID
CInfo.Password = Password
'Set Logon details for main report and each table inside the main report
For Each t In XReport.Database.Tables
TLogonInfo = t.LogOnInfo
TLogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TLogonInf
Next
For Each SubR In XReport.Subreports
For Each t In SubR.Database.Tables
TLogonInfo = t.LogOnInfo
TLogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TLogonInf
Next
Next
End Sub
This procedure explicitly sets the connection details for a report file that connects to SQL Server. Now I need to do exactly the same with MS Access but I'm assuming that different objects / properties / methdos must be used.
From the example in the link I basically need to copy the following logic:
Dim CRXDatabase As CRAXDRT.Database
Set CRXDatabase = CRXReport.Database
CRXDatabase.SetDataSource rs, 3, 1
I'm not using the CRXDRT so this syntax won't work. I can't find the syntax to perform this logic. I need to find the exact syntax for the components that I'm using. I'm using the CrystelDecisions .Net references.
Thanks
ASKER
Thanks habibb,
From the example provided I got the following:
cr1.ReportFileName = App.Path & "\reports\ot1.rpt"
cr1.DataFiles(0) = App.Path & "\otmanag.mdb"
I'm assuming that cr1 is a ReportDocument? My reportdocument doesnt have a DataFiles property. I assume the example also uses a different version of the Crystal API than I am. As in the very first example, this is exactly the logic that I'm trying to perform, only the syntax doesn't fit my API.
Is there perhaps an API guide for the Crystal Reports XI R2 .Net references?
Thanks
From the example provided I got the following:
cr1.ReportFileName = App.Path & "\reports\ot1.rpt"
cr1.DataFiles(0) = App.Path & "\otmanag.mdb"
I'm assuming that cr1 is a ReportDocument? My reportdocument doesnt have a DataFiles property. I assume the example also uses a different version of the Crystal API than I am. As in the very first example, this is exactly the logic that I'm trying to perform, only the syntax doesn't fit my API.
Is there perhaps an API guide for the Crystal Reports XI R2 .Net references?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks stcindia,
I'll try this immediately
I'll try this immediately
ASKER
Dim CInfo As New ConnectionInfo
Dim TlogonInfo As TableLogOnInfo
Dim t As Table
CInfo.ServerName =
For Each t In crRepDoc.Database.Tables
TlogonInfo = t.LogOnInfo
TlogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TlogonInf o)
Next
Dim TlogonInfo As TableLogOnInfo
Dim t As Table
CInfo.ServerName =
For Each t In crRepDoc.Database.Tables
TlogonInfo = t.LogOnInfo
TlogonInfo.ConnectionInfo = CInfo
t.ApplyLogOnInfo(TlogonInf
Next
ASKER
Thank you stcindia
Glad I could help
this link might help you.
https://www.experts-exchange.com/questions/21056406/Crystal-Reports-to-connect-to-the-MS-Access-and-SQL-database-using-ODBC-OLEDB-DSN.html