Help sending ADODC query results to .txt file

I have an application where I have an input form to add data to my database ("Sales").
I have a form where I display all the sales in a DataGrid ("DG1").
I use ADODC1 on each form to connect to the database.

How can I get the results from DG1 to a mulit-line text box or to a .txt file? I would like to see the results on paper that has the header with the information below it.
Like:
DATE       QTY        ITEM          DESCRIPTION         PRICE
-------------------------------------------------------------------
1/1/02       1          1234           Whatever               $ 0.00

Thanks,

Jeff
fanguru1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leonstrykerCommented:
Jeff,

The first thing to do is to get rid of ADODC and use ADO directly.  You would avoid a lot of problems this way.

To display your data in a text file you would most likely use loop through the recordset and write to a file:

http://www.officecomputertraining.com/vbtutorial/tutpages/page24.asp

It maybe easier to output your data to Excel, if you are interested in this method, let me know.

Leon
0
fanguru1Author Commented:
Leon,

Excel would be fine. I'm just looking for an easy way to format the data for printing.

Thanks,

Jeff
0
leonstrykerCommented:
Here is a good example on how to do this:

http://www.vb-helper.com/howto_access_to_excel_2.html

Leon
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fanguru1Author Commented:
Leon,
I took your advise and used the code from access to excel and modified the code to fit my app. Here is the code I used.

Private Sub Command2_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim excel_app As Excel.Application
Dim Excel_Sheet As Excel.Worksheet
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\My Documents\Programming\BS Tree Sales\treelotsales1.mdb"
conn.Open
Set rs = conn.Execute("SALES")
Set excel_app = CreateObject("excel.application")
excel_app.Workbooks.Open App.Path & "\test1.xls"
Excel_Sheet.Cells.CopyFromRecordset rs
Excel_Sheet.Cells.Columns.AutoFit
End Sub

I now get an error on the next to the last line : Excel_Sheet.Cells.CopyFromRecordset rs
My error is Object Variable or With Block Variable not Set!

Can you provide some guidance for me.

Thanks
0
fanguru1Author Commented:
Leon,

I got it to work. I had left out a section.

I would like to be able to input the data on the second or third row to start. I could then put some row headers in. Can you help with that.

Thanks
0
leonstrykerCommented:
Change this:

Excel_Sheet.Cells.CopyFromRecordset rs

To this:

'/ This will place the data starting in the first column of the third row
Excel_Sheet.Range("A3").CopyFromRecordset rs

Leon
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.