output the result to EXCEL

J

James

I added a cmd button in a form that when I click on it, it
runs a stored procedure that uses ActiveX EXE method to
copy a recordset of a query result to an Excel file. What
I need to do is the following:-
after the recordset of the query is copied to the Excel
file, I want to copy the recordset of another query to the
same Excel file and the same workbook. I don't want the
second recordset to overwrite the first recordset from the
first query. I want it to be copied after the last row of
data from the first recordset. What is the code to use for
this?

Hope this wasn't to confusing.

Thanks
 
T

Tim Ferguson

I added a cmd button in a form that when I click on it, it
runs a stored procedure that uses ActiveX EXE method to

I want it to be copied after the last row of
data from the first recordset. What is the code to use for
this?

Rather depends on the syntax and usage of the ActiveX thing you are using.
Can you ask the original programmer, or is it a commercial one?

B Wishes


Tim F
 
A

A. van Huizen

James, use the CurrentRegion command to accomplish this. This method
recognizes the boundary edges of the selected recordset.

e.g.:

Dim objXL As Excel.Application
Dim objWB As Excel.Workbook
Dim objRange As Excel.Range
Dim intCountRows As Integer

Set objXL = New Excel.Application
Set objWB = objXL.Workbooks.Open("C:\Workbook.xls")

objXL.Visible = True

Set objRange = objWB.Worksheets(1).Range("A1").CurrentRegion 'Presume that
Cell A1 is the first cell with the data from recordset 1 !
objRange.Select

intCountRows = objRange.Rows.Count + 2 'add 2 rows for new insert of
recordset

'Start here your CopyFromRecordset with the new location in intCountRows as
your new row heading
' End of
Code------------------------------------------------------------------------
 
J

James

Thank you Arjan. The CurrentRegion command worked well
-----Original Message-----
James, use the CurrentRegion command to accomplish this. This method
recognizes the boundary edges of the selected recordset.

e.g.:

Dim objXL As Excel.Application
Dim objWB As Excel.Workbook
Dim objRange As Excel.Range
Dim intCountRows As Integer

Set objXL = New Excel.Application
Set objWB = objXL.Workbooks.Open("C:\Workbook.xls")

objXL.Visible = True

Set objRange = objWB.Worksheets(1).Range
("A1").CurrentRegion 'Presume that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top