Expand|Select|Wrap|Line Numbers
- Public Sub procOpenMergedDoc(strFilePath As String)
- On Error GoTo ErrorHandler
- Dim strDbFilePath As String
- Dim objWord As New Word.Application
- Dim objDoc As Word.Document
- strDbFilePath = DLookup("DatabaseFilePath", "t_Settings")
- Set objDoc = objWord.Documents.Open(strFilePath)
- objDoc.MailMerge.OpenDataSource Name:=strDbFilePath, LinkToSource:=True, AddToRecentFiles:=False, _
- Connection:="q_Template", SQLStatement:="SELECT * FROM [q_Template]"
- objWord.ActiveDocument.MailMerge.Execute
- objWord.Application.Visible = True
- Exit_Error:
- Set objWord = Nothing
- Set objDoc = Nothing
- Exit Sub
- ErrorHandler:
- MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
- objWord.Quit
- Resume Exit_Error
- End Sub
1) Besides opening the merged Word document it also opens the original Word template. In the one I have setup, I'm merging labels. So I created a label template and inserted my merge fields. However, when this code runs, it opens the merge template showing all the merge fields like <<MailingSal>>, <<AddressLine1>>, etc. along with a word document that has the address data in it. How can I not have the original merge template open but just a Word doc with the merged data?
2) When the Word doc opens, it doesn't open on the screen like when you launch an application. Instead, a Word icon appears in the taskbar and you have to click on it to bring up the doc. Is there a way I can get it to open so that it opens on the screen and the user doesn't think that nothing happened?
Thanks for your help!