I'm experimenting with getting Access to push stuff in and out of Excel using the following code behind two buttons ...
After a lot of messing about with 'Error 2391" (!) this code 'works' in both directions. But, Export absolutely insists on opening a new sheet in the workbook, despite sheet1 being empty, and putting the data in there! As a result, when I click the Import button I get 'Error 2391, Field F1 does not exist in the destination table'. (Of course it doesn't, there isn't an 'F1' name in the first sheet of the workbook, it's in sheet2!)
To get around that error, between the Export and the Import I have to ...
... open the spreadsheet
... delete the first (empty) sheet
... so that, the data exported is one the first sheet of the workbook
... save and close the spreadsheet
THEN the Import works.
This is a bit dotty, isn't it? How can I tell the Export to use 'Sheet 1' of the workbook?
Code:
Private Sub ExportContacts_Click()
'transfer the table CONTACT to the spreadsheet ContactSpSheet
DoCmd.TransferSpreadsheet acExport, , "CONTACT", _
"C:\Users\Owner\Documents\ContactSpSheet"
End Sub
Private Sub ImportContacts_Click()
'transfer the data in spreadsheet ContactSpSheet to the table
'CONTACT_copy ... (Don't mess up the 'real' CONTACT table!!)
DoCmd.TransferSpreadsheet acImport, , "CONTACT_copy", _
"C:\Users\Owner\Documents\ContactSpSheet", True
End Sub
To get around that error, between the Export and the Import I have to ...
... open the spreadsheet
... delete the first (empty) sheet
... so that, the data exported is one the first sheet of the workbook
... save and close the spreadsheet
THEN the Import works.
This is a bit dotty, isn't it? How can I tell the Export to use 'Sheet 1' of the workbook?
Comment