title: Connecting to access backend from access 2013 frontend using VBA
body: <p>I have 5-6 clients to whom I will be selling my Access based Product. Where there is Back-end Database file (Password Protected). Access <code>accdr</code> Front-end file which saves data in back-end file. The location of the backend file will change client to client, hence want to have a VBA Code which links front-end t back-end.</p>
  
  <p>I tried the below code</p>
  
  <pre><code>sConnect = "Provider=Microsoft.ACE.OLEDB.12.0; " _ 
      &amp; Data Source= " &amp; "C:\MyDB_be.accdb" &amp; ";" _ 
      &amp; "Jet OLEDB:Database Password=123;"
  </code></pre>
  
  <p>But, the tables are not getting reconnected.</p>
  
  <p>I Got the above code from <a href="https://stackoverflow.com/questions/15682332/">this Ques on Stackoverflow</a>. </p>
  
  <p>Then I tried the below code </p>
  
  <pre><code>Const LnkDataBase = "C:\MyDB_be.accdb"
  Sub relinktables()
  'Routine to relink the tables automatically. Change the constant LnkDataBase to the desired one and run the sub
  Dim dbs As DAO.Database
  Dim tdf As DAO.TableDef
  Dim strTable As String
  Set dbs = CurrentDb()
  For Each tdf In dbs.TableDefs
      If Len(tdf.Connect) &gt; 1 Then 'Only relink linked tables
          If tdf.Connect &lt;&gt; ";DATABASE=" &amp; LnkDataBase Then 'only relink tables if the are not linked right
              If Left(tdf.Connect, 4) &lt;&gt; "ODBC" Then 'Don't want to relink any ODBC tables
                  strTable = tdf.Name
                  dbs.TableDefs(strTable).Connect = ";DATABASE=" &amp; LnkDataBase
                  dbs.TableDefs(strTable).RefreshLink
              End If
          End If
      End If
  Next tdf
  End Sub
  </code></pre>
  
  <p>This works, when the file is not password protected. This code I got from <a href="https://stackoverflow.com/questions/4928134">This Ques</a>. But there is no provision of specifying password.</p>
  
  <p>Please help me out.</p>
  
  <blockquote>
    <p>Either point out mistake in 1st code. OR How to specify password in
    2nd Code OR New code altogether.</p>
  </blockquote>
  
  <p>Spent 4 hrs on searching for solution. New to access VBA.</p>
  
  <p>Went through <a href="https://www.connectionstrings.com/access-2013/" rel="nofollow noreferrer">this</a> and <a href="http://www.freevbcode.com/ShowCode.asp?ID=468" rel="nofollow noreferrer">this</a>, but did not understand how to implement.</p>