I am having trouble linking a report to a database in code, I've worked through all the examples I can find in the manuals and had a whole range of different problems. Currently the code I'm using is as follows:
Dim TestReport As CrystalReport1
Dim rst As adodb.Recordset
Dim SQLstring As String
Dim strConString As String
Set TestReport = New CrystalReport1
SQLstring = "SELECT SR.Description,SA.SaleDate AS [Date of Sale] FROM Sales AS SA, Products AS SR;"
Set rst = CreateObject("ADODB.Recordset"
rst.Open SQLstring, "Database=c:\windows\desktop\test.mdb;uid=;pwd=admin;dsn=TestData", adUseServer, adModeRead"
TestReport.Database.SetDataSource rst
TestReport.UnboundString1.SetUnboundFieldSource ("{Description}"
I get the error message: 'Field Name is Not Known'. To me this seems to indicate that the database is not connecting, prior to this I was getting the error 'Subscript out of Range' (on the SetDataSource command) I don't know what I changed but it was nothing major. If anyone can provide a solution or suggest where I might find one please let me know.
This is very important as we need to be able to change the name and location of the database at runtime.
Dim TestReport As CrystalReport1
Dim rst As adodb.Recordset
Dim SQLstring As String
Dim strConString As String
Set TestReport = New CrystalReport1
SQLstring = "SELECT SR.Description,SA.SaleDate AS [Date of Sale] FROM Sales AS SA, Products AS SR;"
Set rst = CreateObject("ADODB.Recordset"
rst.Open SQLstring, "Database=c:\windows\desktop\test.mdb;uid=;pwd=admin;dsn=TestData", adUseServer, adModeRead"
TestReport.Database.SetDataSource rst
TestReport.UnboundString1.SetUnboundFieldSource ("{Description}"
I get the error message: 'Field Name is Not Known'. To me this seems to indicate that the database is not connecting, prior to this I was getting the error 'Subscript out of Range' (on the SetDataSource command) I don't know what I changed but it was nothing major. If anyone can provide a solution or suggest where I might find one please let me know.
This is very important as we need to be able to change the name and location of the database at runtime.