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?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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 & ";"
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top