Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A little help with paste into excel required...

Status
Not open for further replies.

ooch1

MIS
Nov 4, 2003
190
GB
Hello,

I'm trying to paste some data from access into excel, but am currently only succeeding with the column headers.

My Copy and Paste Code is:
With objWorkbook.Worksheets("MonthlyView").range("A2")
For i = 0 To rs.Fields.Count - 1
.offset(-1, i) = rs.Fields(i).Name
Next
Set xlRng = objWorkbook.Worksheets("MonthlyView").range ("a2")
'copy in the data
xlRng.CopyFromRecordset rs
End With


Can someone please tell how to get the data in as well, plus help with why it is not currently working, then a star will surely be yours???

OOch
 
what error are you getting and where do you set rs ??

Also, why bother seeting xlRng if you are only going to use it once ?

you are already using that range in the WITH clause so:
Code:
With objWorkbook.Worksheets("MonthlyView").range("A2")
    For i = 0 To rs.Fields.Count - 1
        .offset(-1, i) = rs.Fields(i).Name
    Next
    .CopyFromRecordset rs
End With
should work fine as long as rs is a recordset

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top