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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with CopyFromRecordset

Status
Not open for further replies.

cbd

Programmer
Apr 4, 2002
18
US
I am using Access 97 to transfer records into an excel spreadsheet, I keep getting the follow error :

run-time error '-2147417851 (80010105)'
Method 'CopyFromRecordset' of object 'Range' failed

The code actually does copy the records into excel but then displays the above error in Access. I believe it might have something to do with the fact I was gathering the info for the recordset from different tables, but now I am getting the information from just 1 table and it is still giving me the error. Any ideas on how to solve this

Here is the code i am using :

Private Sub Output_Click()
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set objXL = New Excel.Application
Set rs = db.OpenRecordset("All Records", dbOpenSnapshot)
With objXL
.visible = True
Set objWkb = .Workbooks.Open("C:\My Documents\Report.xls")
Set objSht = objWkb.Worksheets("All Data Input")
objSht.Range("A2").CopyFromRecordset rs
End With

Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
Set rs = Nothing
Set db = Nothing

End Sub
 
I can't find anything wrong with your code. I tried it with my own tables and files and no errors... Perhaps so long as it works simply shut off the error message.
 
Thanks for the help. It could just be the old computer I am using. I'll just ignore the error message as you advised.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top