Reputation: 1
I continue to get a user-defined error. This code is very helpful in exporting data to access. It just won't kick off because of the User-defined error.
Thank you
Public Sub AccImport()
Dim acc As DAO.Database
acc.OpenCurrentDatabase "C:\Users\public\Database1.accdb"
acc.DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel12Xml, _
"tblExcelImport", _
Application.ActiveWorkbook.FullName, _
True, _
"Folio_Data_original$A1:B10"
acc.CloseCurrentDatabase
acc.Quit
Set acc = Nothing
End Sub
Upvotes: 0
Views: 140
Reputation: 19367
You should tell us which line the error refers to, but it is most likely the second.
You need to add a reference to the DAO library. Go to Tools, References and find and tick Microsoft DAO 3.6 Object Library, so that you can then use DAO.
in your code.
But OpenCurrentDatabase
is an Access method. To use this, and then call TransferSpreadsheet, you need to use Access Automation. This involves:
Then you can use OpenCurrentDatabase
and TransferSpreadsheet
.
Upvotes: 2