Alex Kurama


Dear all,

I would know how can I export the access resultset to excel. Can I get the query from Access which I have done and saved in access directly, so that I do not need to rewrite the SQL statement in the VB, if yet, then how I think I need to use something like

Set rs = db.OpenRecordset("Query name") or such

but I don't know how. Can anyone of you can help me in this issue Thanks in advance.

Regards,

Alex





Re: Exporting the access resultset to excel programmatically

Shasur


You can use the CopyFromRecordset method for that:

Code Snippet

sQuery = "Select * From Products"

RS.ActiveConnection = Cn
RS.Source = sQuery
RS.Open

If RS.EOF = True And RS.BOF = True Then
'Cells(i1, iRevCol).Value = "N/A"
GoTo TakeNextRecord
End If


RS.MoveFirst
Activeworkbook.Sheets(1).Range("A2").CopyFromRecordset RS

Cheers

Shasur