run-time error -2147467259 (80004005)
Hi all,
I would like to add data from an access query into excel with this code but it prompts me with this error:
Run time error -2147467259 (80004005)
Automation error
Unspecified error
this is the code I found on the internet.
Could someone have look where it is failing, im new with VBA and dont have clue.
Option Explicit
Sub Execute_StoredQuestion_Dataimport()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stDB As String, stSQL As String, stConn As String
Dim wsSheet As Worksheet
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
Set wsSheet = ThisWorkbook.Worksheets(1)
stDB = ThisWorkbook.Path & "\test.mdb"
'Since the database is passwordprotected we need to
'add the password to get access to it.
stConn = "Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & stDB
'The name of the stored question is placed between the brackets.
'stSQL = "[Access_Question]"
wsSheet.Range("A1").CurrentRegion.Clear
cnt.Open stConn
rst.Open stSQL, cnt
wsSheet.Cells(2, 1).CopyFromRecordset rst
rst.Close
Set rst = Nothing
cnt.Close
Set cnt = Nothing
End Sub
|