Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Supply password when linking Access tables programmatically with VBA

Avatar of 1104d
1104dFlag for Australia asked on
Microsoft Access
7 Comments1 Solution1016 ViewsLast Modified:
I have some code I have used successfully for some years to link back-end tables programmatically to front end tables in an Access 2003 application.  The code is shown below.

The back end database now needs to be password protected.  How do I add a password parameter into the code below or tell the application the password?  I do not wish to start again with this code, just to add the appropriate parameter or code into the existing subroutine.

Thank you.
Private Sub b_ReattachTables_Click()
On Error GoTo Err_b_ReattachTables_Click
Dim strPrgFilePath As String
Dim strPrgFileName As String
Dim strPrgFileFolder As String
strPrgFilePath = Application.CurrentDb.Name
strPrgFileName = Dir(strPrgFilePath)
strPrgFileFolder = Left(strPrgFilePath, Len(strPrgFilePath) - Len(strPrgFileName))
Dim tdf As DAO.TableDef
For Each tdf In DBEngine(0)(0).TableDefs
If ((tdf.Attributes And dbSystemObject) = 0) And (tdf.Connect <> vbNullString) And Not (tdf.Name Like "~*") Then
    tdf.Connect = ";DATABASE=" & Trim(strPrgFileFolder) & "BACKEND.mdb" 
    Me!lblMsg.Caption = "Linking..." & tdf.Name
End If
Me!lblMsg.Caption = ""
MsgBox "Linked tables have been re-attached", 64, "Attach Tables"
    Exit Sub
    MsgBox "Please add back-end files to the current directory!", vbCritical, "Error No 3."
    Resume Exit_b_ReattachTables_Click
End Sub