thread705-1525294
Somehow this thread got closed and not resolved, so I am opening it up again...
Thanks Hennie but there seems to be a few things missing.
I added DIM statements at the top of the code below along with the End With but the code crashes
with an Object required message on the Set Rs1 line.
What other definitions are needed for this?
Thanks
Somehow this thread got closed and not resolved, so I am opening it up again...
Good day,
I normally do not use the Transferspreadsheet function but rather CopyFromRecordset function. You can specify where you want to place the data and if needed any formating can be done from within Access. I find this method easier to use.
Below is an answer I gave someone a few months ago. Try it and see if it helps.
I use a different method to export data from Access to Excel. I copy the whole table/query to the sheet with the steps indicated below. It is an extract of the method I use for all data exported to Excel and do most of the formatting from within Access.
If need you could trasfer the data to a different work sheet and then from within Excel append it to the table in Excel or do a row count via Access in Excel and use that number to append it from there.
Remember to synchronize your query with the columns in Excel if you copy directly into and existing table.
Hope this helps.
Hennie
Set objExcel = CreateObject("Excel.Application")
'Run qryMisaRSP and transfer data to sheet RSP for annual statistics.
Set rs1 = db.OpenRecordset("tblMisaRSP", dbOpenSnapshot)
'Set the object variable to reference the file you want to see.
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME1) 'RSP
objWkb.Worksheets("RSP").Activate
objWkb.Windows("RSP").Visible = True
With objSht
'Copy data from the two record sets
.Range("A2").CopyFromRecordset rs1
Thanks Hennie but there seems to be a few things missing.
I added DIM statements at the top of the code below along with the End With but the code crashes
with an Object required message on the Set Rs1 line.
What other definitions are needed for this?
Thanks
Code:
Dim rs1 As Recordset
Dim objExcel As Object
Set objExcel = CreateObject("Excel.Application")
'Run Ord_tbl_qry and transfer data from Ord_tbl to sheet Order for Sales Order information.
Set rs1 = db.OpenRecordset("Ord_tbl", dbOpenSnapshot)
'Set the object variable to reference the file you want to see.
With objXL
.Visible = True
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME1) 'RSP
objWkb.Worksheets("RSP").Activate
objWkb.Windows("RSP").Visible = True
With objSht
'Copy data from the two record sets
.Range("A2").CopyFromRecordset rs1
End With
End With