Code for connecting to an encrypted / password protected database

At startup, my front end front.accdr database contacts the back of back.accde using:

DoCmd.TransferDatabase acLink, "Microsoft Access", "back.accde", acTable, "aTable", "aTable"

The back end really needs encryption, so I need to use a password to connect to an encrypted database. How should I do it?

+3
source share
2 answers

The method I used for this is actually quite simple:

Set db = CurrentDb
Set dblink = DBEngine.OpenDatabase(strDbFile, False, False, ";PWD=" & strP)

For Each strTable In strLinkedTablesArray
     DoCmd.TransferDatabase acLink, "Microsoft Access", dblink.name, acTable, _
         strTable, strTable
Next
+4
source

If you cannot find a way to enable the database password with TransferDatabase, you can create a table link as a new member of the collection DAO.TableDefs.

I confirmed that this code works in an Access 2007 ACCDR file.

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConnect As String
Dim strDbFile As String
Dim strLinkName As String
Dim strPassword As String
Dim strSourceTableName As String

strDbFile = "C:\share\Access\PasswordEquals_foo.accdb"
strPassword = "foo"
strSourceTableName = "Contacts"
strLinkName = "link_to_contacts"

strConnect = "MS Access;PWD=" & strPassword & _
    ";DATABASE=" & strDbFile
Debug.Print strConnect
Set db = CurrentDb
Set tdf = db.CreateTableDef
tdf.Connect = strConnect
tdf.SourceTableName = strSourceTableName
tdf.Name = strLinkName
db.TableDefs.Append tdf

, ACCDR , link TableDef.Connect, . , "MS Access, PWD = foo; DATABASE = C:\share\Access\PasswordEquals_foo.accdb" Immediate.

Dim dbRemote As DAO.Database
Dim objWorkspace As Workspace
Set objWorkspace = CreateWorkspace("", "admin", "", dbUseJet)
Set dbRemote = objWorkspace.OpenDatabase("C:\share\Access\Database2.accdr")
Debug.Print dbRemote.TableDefs("link_to_contacts").Connect
dbRemote.Close
objWorkspace.Close

, db.

+4

All Articles