user3670573
user3670573

Reputation: 1

User Defined type not defined

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

Answers (1)

Andy G
Andy G

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:

  • Having a Reference to the Access Object Library
  • Creating a new instance of the Access Application, and having an object variable that refers to this new instance

Then you can use OpenCurrentDatabase and TransferSpreadsheet.

Upvotes: 2

Related Questions