Thanks for any help.
I have been using the below method to query my Access database from Excel VBA for over a decade. Today it started throwing an unspecified error. I tried all the usual suspects (reboot, reinstall, switch PC, access files from local machine instead of network, checking reference libraries) but I can't seem to find an issue. I'm running Windows 10 and Office 2016.
Is there another method to do the same thing? Thanks very much.
It's breaking on the line: con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AccessFile
Public Function getRSOLD(sSQL As String) As Variant
Dim con As ADODB.Connection, rs As ADODB.Recordset
Dim AccessFile As String
Dim Rw As Long, Col As Long, c As Long
Dim MyField, Location As Range
'specify path to db
AccessFile = dbPath 'string variable with file location
On Error Resume Next
'Create the ADODB connection object.
Set con = CreateObject("ADODB.connection")
'Check if the object was created.
If Err.Number <> 0 Then
MsgBox "Connection was not created!", vbCritical, "Connection Error"
Exit Function
End If
On Error GoTo 0
'Open the connection.
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AccessFile
On Error Resume Next
'Create the ADODB recordset object.
Set rs = CreateObject("ADODB.Recordset")
'Check if the object was created.
If Err.Number <> 0 Then
'Error! Release the objects and exit.
Set rs = Nothing
Set con = Nothing
'Display an error message to the user.
MsgBox "Recordset was not created!", vbCritical, "Recordset Error"
Exit Function
End If
On Error GoTo 0
'Set thee cursor location.
rs.CursorLocation = 3 'adUseClient on early binding
rs.CursorType = 1 'adOpenKeyset on early binding
'On Error Resume Next
'Open the recordset.
rs.Open sSQL, con
Set getRSOLD = rs
Set Location = Nothing
Set con = Nothing
Set rs = Nothing
End Function