Automation error - when connecting to 2010 accdb password protected database from excel 2007 vba

dawood_s

New Member
Joined
Mar 12, 2008
Messages
15
I get Automation error when connecting to 2010 accdb password protected database from excel 2007 vba. The code is as below :'DIM STATEMENTSDim strMyPath As String, strDBName As String, strDB As String, strQuery As String, strMyDBPassword As StringDim i As Long, n As Long, lFieldCount As LongDim rng As Range'instantiate an ADO object using Dim with the New keyword:Dim adoRecSet As New ADODB.RecordsetDim connDB As New ADODB.Connection'--------------'THE CONNECTION OBJECTstrDBName = "33mSTUPV2.accdb"strMyPath = "v:\Arch_33"strDB = strMyPath & "\" & strDBNamestrMyDBPassword = "abcde"'strMyDBPassword = ""strQuery = "ds_Query1"connDB.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDB & ";Jet OLEDB:Database Password=strMyDbPassword;"If i remove the password on the accdb file and try the above code with strMyDBPassword="", I am able to connect and proceed further.I want the code to work with the password on the accdb file.Can someone hlep. please?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,338
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
If I remember correctly there is an issue with the encryption method used from 2010 - you need to ensure the database uses a lower encryption method that is backwards compatible.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,338
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Open it in Access, remove the password, then go into File - Options, select the Client Settings section, and at the bottom, check the "use legacy encryption" option, then add the password again.
 

dawood_s

New Member
Joined
Mar 12, 2008
Messages
15
Thanks for the help.However, even after setting the "use legacy encryption" , I am getting the Automation error.Could this error be related t osmething else? Strange thing is that I do not get the error when the Access database is not password protected.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,338
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Ah, I misread your code in the original post - you have included the password variable as part of the literal connection string, so it is passing the actual text "strDBPassword" as the password. You need:
Code:
'DIM STATEMENTS
Dim strMyPath As String, strDBName As String, strDB As String, strQuery As String, strMyDBPassword As String
Dim i As Long, n As Long, lFieldCount As Long
Dim rng As Range
'instantiate an ADO object using Dim with the New keyword:
Dim adoRecSet As New ADODB.Recordset
Dim connDB As New ADODB.Connection
'--------------
'THE CONNECTION OBJECT
strDBName = "33mSTUPV2.accdb"
strMyPath = "v:\Arch_33"
strDB = strMyPath & "\" & strDBName
strMyDBPassword = "abcde"
'strMyDBPassword = ""
strQuery = "ds_Query1"
connDB.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDB & ";Jet OLEDB:Database Password=" & strMyDbPassword & ";"
 

dawood_s

New Member
Joined
Mar 12, 2008
Messages
15
RoryA,Thanks a lot. It has worked. Should I now try to restore the envryption level of Accesss 2010 to its default and check my Excel 2007 macro?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,338
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Yes, why not? ;)
 

Forum statistics

Threads
1,081,981
Messages
5,362,535
Members
400,679
Latest member
alecalec202

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top