1

This is the code I use to open a connection to an access database from excel. It used to work for more than a year.

Set dbname = New ADODB.Connection
theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open theconnection
End With

By trial an error I've come to the conclusion that this line is causing the problem.

Set dbname= New ADODB.Connection

The problem began after an automatic update of my PC My Excel version 2016 MSO (16.0.7726.1036) 32-bit

Please let me know if you have run also into this problem, and if you know any fix or workaround.

2 Answers 2

1
  • try to uncheck your 'ActiveX Data Objects' references and add them back:

Tools - References

or

  • use object to define a database:

     Dim dbname As Object
     Set dbname = CreateObject("ADODB.Connection")
    

or

if you create connection variable like this:

Dim con as New ADODB.Connection

change it to:

Dim con as ADODB.Connection
Set con = New ADODB.Connection
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the hints. The problem is solved. When I checked the References, I had Microsoft ActiveX Data Objects 6.0 Library checked. When I unchecked it, it disappeared. Looks like during some of the office 365 upgrades, it was changed for version 6.1. When I checked this version it began to work again. Thanks for your help again.
0

Maybe

Dim dbname As Object
Set dbname = CreateObject("ADODB.Connection")

theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open theconnection
End With

I used like this , all code

Dim Rs As Object
Dim strConn As String
Dim i As Integer
Dim strSQL As String

strSQL = "select * from [table] "
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
        "Extended Properties=Excel 12.0;"


Set Rs = CreateObject("ADODB.Recordset")
Rs.Open strSQL, strConn

If Not Rs.EOF Then
     With Ws
        .Range("a1").CurrentRegion.ClearContents
        For i = 0 To Rs.Fields.Count - 1
           .Cells(1, i + 1).Value = Rs.Fields(i).Name
        Next
        .Range("a" & 2).CopyFromRecordset Rs
    End With
End If
Rs.Close
Set Rs = Nothing

2 Comments

I tried this, but it didn't solve the problem. It was the Microsoft ActiveX library upgrade that created this problem. Thanks for helping.
@MarcinDramiński: I modified my answer, full code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.