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

Problem connecting a Database @ runtime

Status
Not open for further replies.

ArtInter

Programmer
Nov 8, 2000
3
AU
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top