UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Mail Merge Automation Mdb Vs Accdb, Office 2013    
 
   
melcat
post Jul 7 2017, 11:33 AM
Post#1



Posts: 14
Joined: 2-May 17



I'm having all kinds of issues with Mail Merge Automation. Does it even work with an ACCDB??

Found this from HiTechCoach http://hitechcoach.com/microsoft-office/ac...-merge/download
He had a thread that sounded intriguing but can't download at work.

My issue is even after creating a new document, when I run the merge, it tells me it 'Could not find file XXX' which is either
C:\AAA Database.mdb" or "T:\AAA Database\Database Support Folder\AAA Database Backside\AAA Database.mdb"
depending on whether I point to C drive or network T drive.

I'm in Access accdb.
Each time I try to save as the network source, it appears to save until I run again and get the error again.

I am running
CODE
Private Sub cmdAdminData_Click()
On Error GoTo Err_cmdadmindata
Dim strDocumentName As String
Dim strMailMergeConn As String
Dim strMailMergeQuery As String

    strDocumentName = "T:\AAA Database\Database Support Folder\AAA Database Backside\(U) AAA Mission Report Template ADMIN.docx"

    strMailMergeConn = "tblMMMainData"
    strMailMergeQuery = "tblMMMainData"

    Merge_Data strDocumentName, strMailMergeConn, strMailMergeQuery
    Exit Sub
    
Err_cmdadmindata:
    MsgBox Err.Number & " " & Err.Description
    Resume Next
End Sub


Private Sub Merge_Data(strDocName As String, strConn As String, strSQL As String)
Dim objWordApp As Object
Dim objDoc As Object

On Error GoTo Err_Merge_Data

    'Set up the Word app and doc
    Set objWordApp = CreateObject("Word.Application")
    
    Set objDoc = objWordApp.Documents.Open(strDocName)
    objWordApp.Visible = True

    objDoc.MailMerge.OpenDataSource _
    Name:="T:\AWG Database\Database Support Folder\AWG Database Backside\AWGDataBE.accdb", _
        LinkToSource:=True, AddtoRecentFiles:=False, _
        Connection:="TABLE [strConn]", _
        SQLStatement:="SELECT * FROM '" & [strSQL] & "'"
    objDoc.MailMerge.Destination = wdSendToNewDocument
    objDoc.MailMerge.Execute

    'closes 2nd occurance which is the template
    objWordApp.Application.Documents(2).Close wdDoNotSaveChanges

Exit_Merge_Data:

    Set objWordApp = Nothing
    Set objDoc = Nothing
    Exit Sub

Err_Merge_Data:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Merge_Data

End Sub


I'm going to say I have tried almost all the items I could fiind that people have written about saving the Data Source for the Word template and nothing is working.

thank you for any help
Go to the top of the page
 
Doug Steele
post Jul 7 2017, 12:16 PM
Post#2


UtterAccess VIP
Posts: 21,490
Joined: 8-January 07
From: St. Catharines, ON (Canada)


This part of your code looks suspect:

CODE
    objDoc.MailMerge.OpenDataSource _
    Name:="T:\AWG Database\Database Support Folder\AWG Database Backside\AWGDataBE.accdb", _
        LinkToSource:=True, AddtoRecentFiles:=False, _
        Connection:="TABLE [strConn]", _
        SQLStatement:="SELECT * FROM '" & [strSQL] & "'"

See whether this works any better:

CODE
    objDoc.MailMerge.OpenDataSource _
    Name:="T:\AWG Database\Database Support Folder\AWG Database Backside\AWGDataBE.accdb", _
        LinkToSource:=True, AddtoRecentFiles:=False, _
        Connection:="TABLE [" & strConn & "]", _
        SQLStatement:="SELECT * FROM [" & strSQL & "]"


Take a look at OpenDataSource method for more details.

--------------------
Go to the top of the page
 
melcat
post Jul 7 2017, 01:06 PM
Post#3



Posts: 14
Joined: 2-May 17



Doug,
good catch
That worked, thank you
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    10th December 2017 - 09:27 PM