I have an access database in which I use an Import Wizard add-on to populate data into my tables. I have a form with a button which runs the following code in order to automate the process. When I click on the button, I get Import Failed. (exit code 2) and when I check the error log it reads: Unable to cast object of type 'System.__ComObject' to type 'dao.DBEngineClass'. Any ideas?
Private Const iwAddInName As String = "IW10DLL.ImportWizardAddIn"
Private Sub SDLH_Import_Click()
Dim iw As Object, result As Long
If vbCancel = MsgBox("This this is an Import Wizard automation. Press OK to import 'SDLH Historical Detail Report'.", vbOKCancel, "Import Wizard Automation") Then
Exit Sub
End If
Set iw = Application.COMAddIns(iwAddInName).Object
result = iw.ImportWizardGo("Historical_Detail_New.iwm", , "tbl_SDLH_NEW")
Select Case result
Case 2:
MsgBox "Import Failed. (exit code 2)", , "Import Wizard Automation"
Case 1:
DoCmd.OpenTable "tbl_SDLH_NEW"
MsgBox "Import completed with warnings. (exit code 1)", , "Import Wizard Automation"
Case Else
DoCmd.OpenTable "tbl_SDLH_NEW"
MsgBox "Import completed OK. (exit code " & result & ")", , "Import Wizard Automation"
End Select
End Sub