954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connection strings for DataReport

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

johntech2001
Newbie Poster
4 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

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"

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

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!

johntech2001
Newbie Poster
4 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

It was a pleasure. Happy coding.:)

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

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You