I am working through the book Beginning Visual Basic 6 Database Programming by John Connell. I have finished the section on Building a Data Control Class Module and have created a nice Book List program for my wife. I am using the DAO database control as shown in the book. In one of my other books I learned how to setup and use the Data Reporting option in VB6. In trying to make my code more portable I have changed the pointer to my database by using "App.Path" to point to the database but the DataReport is hard coded using the DataEnvironment, Connect and Command options in it. It prints out a nice listing of all the books my wife is looking to read (6 pages worth!!) I am looking for some help in figuring out how to setup the DataReport without being hard coded so I can use "App.Path" to point to the database. Once I figure out this the program will be done and I can move on to the next chapter and new program challanges.

Any help or information you can provide will be greatly appreciated
John

Create a data access object -

Dim MyConnection As ADODB.Connection
Set MyConnection = New ADODB.Connection

Dim MyReport As ADODB.Recordset
Set MyReport = New ADODB.Recordset

Open the connection and the recordset by using a Sql Statement -

MyReport.Open "SELECT * FROM MyWifesBooks ORDER BY Author", MyConnection,adOpenStatic, adLockOptimistic

If there are records available in the recordset, set your data report's datasource to your recordset, MyReport.

Set MyDataReport.Datasource = MyReport.Recordset

Have a look at the following Daniweb post -http://www.daniweb.com/forums/thread210752.html,
or search on google for tons of other samples - "set datasource in vb6 datareport"

I tried your code and for some reason it did not work. I did more reading in my books and did put together some working code similar to yours that printed out the report I needed. Thank you for your code segments!

It was a pleasure. Happy coding.:)

Please mark this as solved if you will not be using this post anymore, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.