title: Access / Word 2010 VBA Mail Merge Tries to Open [Foldername].mdb Instead of ACCDB Source
body: <p>We are attempting to automate a mail merge process from within Access - upon clicking a button, VBA runs that specifies the current database (an accdb) as the data source and runs SQL, per the code below:</p>
  
  <pre><code>'Set up Word
  Dim objWord As Object
  Set objWord = CreateObject("Word.Application")
  
  'Make visible, open specified doc to merge
  With objWord
      .Visible = True
      .Documents.Open strDocName
  End With
  
  'Set the data source path
  Dim docPath As String
  docPath = CurrentProject.Path &amp; "\" &amp; CurrentProject.Name
  
  'Open the merge data source - simplified
  objWord.activedocument.mailmerge.opendatasource _
      Name:=docPath, _
      SQLStatement:=strSQL
  </code></pre>
  
  <p>strDocName and strSQL are passed in and contain valid, functional contents.</p>
  
  <p>It succeeds in opening word, making it visible and opening the template to merge into. At that point, however, it comes up asking to confirm data source, and shows a list of possible data sources. Upon clicking the 'show all' checkbox, I can scroll down to MS Access Database via ODBC (.mdb, .accdb) and select it from the list.</p>
  
  <p>It then presents with a box titled 'ODBC Microsoft Access Driver Login Failed', saying 'Could Not Find File: "[path to database folder]/[name of containing folder].mdb"'</p>
  
  <p>So, if my database were located in C:\Temp the error path would read 'C:\Temp.mdb'. Moving the access database to another folder causes the error path to update looking for an accordingly named mdb file based on the containing folder.</p>
  
  <p>I don't know if it's relevant but it also appears to be opening the template in the mode for editing the template itself, rather than generating a new document from that template.</p>
  
  <p>Am I missing something here or does anyone have any ideas?</p>
  
  <p>Cheers</p>
  
  <hr>
  
  <p>With the assistance of Remou below, we gave up linking directly to Access and used the code from Remou's suggested link to output to a temporary text file, then merge from there.</p>
  
  <p>We modified the code to remove CurrentBackendPath() and changed the only reference to this function as follows:</p>
  
  <pre><code>Private Function GetStartDirectory() As String
      'GetStartDirectory = CurrentBackendPath() &amp; "mm\"
      GetStartDirectory = CurrentProject.Path &amp; "\mm\"
  End Function
  </code></pre>
  
  <p>The only other modifications we used were to change the code to be specific to our purpose. Thanks once again to everyone for your replies. I would upvote Remou for their response if I had enough reputation to do so!</p>