I'm working on Excel VBA macros and I want to retrieve data from a MS Access database (.accdb
file).
I've tried using below connection string and it throws runtime error '438'
Dim cn As Object, rs As Object,DBFullName As String,Target As Range
DBFullName = "D:\Tool_Database\Tool_Database.accdb"
Set Target = Sheets("Sheet1").Range("A1")
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBFullName & ";"
Set rs = CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM test", cn, , , adCmdText
For int i = 0 To rs.Fields.Count - 1
Target.Offset(1, i).Value = rs.Fields(i).Name
Next
Target.Offset(1, 0).CopyFromRecordset rs
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
PLease help me to resolve the error
.accdb
file - then why are you usnig an.mdb
extension in your connection string??DBFullName = "D:\Tool_Database\Tool_Database.mdb"
?? – marc_s