0
votes

I have created a application that takes an Excel file and inserts it into my access database table. I used Microsoft Access 15.0 Object Library in my computer . But when I executed the application it in an another computer with Access 2007 it stops immediately. This is the code:

Private Sub xlsTomdb()
    On Error GoTo err_handler
    Dim oAccess As Access.Application
    Set oAccess = CreateObject("Access.Application")
    oAccess.Visible = False
    oAccess.OpenCurrentDatabase App.Path + "\archivi.mdb", True
    oAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "EXCEL", App.Path + "\Export\Final.xls", True
    oAccess.Quit
err_handler:
      MsgBox "The code failed at line " & Erl, vbCritical
End Sub

The msgBox shows "The code failed as line 0". When I removed the Error Handler the program continues the execution normally. While running the program on another PC with Office 2007 it terminates at this function with runtime error [-2147467259 (80004005) microsoft odbc microsoft access driver type mismatch in expression]

This function is executed on button click event. Is there any reason not to open access 2007, because I used Access 2013 while building it?

Can anyone help?

2
Any reason why you have not declared the oAccess object?PaulFrancis
the declaration is at the top of of the code, this is only the functionEBalla
Please update the code with the declaration. Also where are you executing this function from? Application is Access?PaulFrancis
You could try Dim oAccess As Object instead of Dim oAccess As Access.ApplicationGord Thompson
I notice that you have a spelling error on 'Acccess.Application' Have you tried to compile your code, and is that realllly the way it is spelled?Wayne G. Dunn

2 Answers

0
votes

EBalla:

"Microsoft Access 15.0 Object" or DAO 15 library belongs to office 2013. Earlier versions will not know about this library. if your target machines are using office 2007 you need to add the reference "Microsoft Access 12.0 Object library" into your project. You are experiencing compatibility issue rather than code issue.

also check this out: http://allenbrowne.com/ser-38.html

0
votes

Just substitute the follow sentence... Its work fine with any interop referenced in Project...

from:

Dim oAccess As Access.Application
Set oAccess = CreateObject("Access.Application")

to:

Dim oAccess As object
Set oAccess = CreateObject("Access.Application")