简体   繁体   中英

How can I connect to a ms-access database from vba in excel?

I'm trying to connect to an ms-access database from Excel by using VBA code, but I receive the error message "not valid password". I have an office 365 subscription.

I have tried passwords with only numbers, only words, putting a ";" character at the end of the password.

Set cn = CreateObject("ADODB.Connection")
conexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Jet OLEDB:Database Password=MyDbPassword"
cn.Open conexion

From Connectionstrings.com :

Microsoft ACE OLEDB 12.0

Standard security

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\myFolder\\myAccessFile.accdb; Persist Security Info=False;

With database password

This is the connection string to use when you have an Access 2007 - 2013 database protected with a password using the "Set Database Password" function in Access.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\myFolder\\myAccessFile.accdb; Jet OLEDB:Database Password=MyDbPassword;

Some reports of problems with password longer than 14 characters. Also that some characters might cause trouble. If you are having problems, try change password to a short one with normal characters.

Note! Reports say that a database encrypted using Access 2010 - 2013 default encryption scheme does not work with this connection string. In Access; try options and choose 2007 encryption method instead. That should make it work. We do not know of any other solution. Please get in touch if other solutions is available!


Based on their recommendation try to change the password to a short one under 14 characters .

Additionally, in your example, you did leave off the semicolon ; after your password.

Solved. I quote this solution posted here :

"(...)First of all, remove the password, and then go into Access->File->Options->Client Settings->Advanced and check "use legacy encryption". Now we can recreate the password and give it a try."

Keep in mind this option is less safe than "use predetermined encryption"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM