Hi all I am using the following code done by Fizzio(found in another thread) to my mail merge.
Public Sub MergeToWord(strDocName As String, MyQuery as String)
Dim objApp As Object
'Change cursor to hourglass
DoCmd.Hourglass True
'Open Mailmerge Document
'Start Word
Set objApp = CreateObject("Word.Application")
With objApp
.Visible = True 'Make it visible
.Documents.Open strDocName 'Open the Mailmerge Document
'Use the Query defined in the arguments as the datasource
.ActiveDocument.MailMerge.OpenDataSource Name:=CurrentDb.Name, Connection:="QUERY " & MyQuery
End With
'Create, print and close Document
With objApp
.ActiveDocument.MailMerge.Execute 'execute mailmerge
.ActiveDocument.PrintOut Background:=False, Copies:=1 'print out 1 copy
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges 'Avoid Saving over your template
.Quit SaveChanges:=wdDoNotSaveChanges 'close all documents
End With
Set objApp = Nothing
ErrorHandler:
Select Case Err.Number
Case 4157
End Select
DoCmd.Hourglass False 'Cursor back to normal
End Sub
My Problem is that when the mailmerge is performed the word documents brings up a list of datasources to choose from....it should be automated. When I select the query everything works as expected.
Also my document does not have any data linked to it that is I have made it a 'Normal Document'. Any advice will be appreciated.
Thanks
Karv
Public Sub MergeToWord(strDocName As String, MyQuery as String)
Dim objApp As Object
'Change cursor to hourglass
DoCmd.Hourglass True
'Open Mailmerge Document
'Start Word
Set objApp = CreateObject("Word.Application")
With objApp
.Visible = True 'Make it visible
.Documents.Open strDocName 'Open the Mailmerge Document
'Use the Query defined in the arguments as the datasource
.ActiveDocument.MailMerge.OpenDataSource Name:=CurrentDb.Name, Connection:="QUERY " & MyQuery
End With
'Create, print and close Document
With objApp
.ActiveDocument.MailMerge.Execute 'execute mailmerge
.ActiveDocument.PrintOut Background:=False, Copies:=1 'print out 1 copy
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges 'Avoid Saving over your template
.Quit SaveChanges:=wdDoNotSaveChanges 'close all documents
End With
Set objApp = Nothing
ErrorHandler:
Select Case Err.Number
Case 4157
End Select
DoCmd.Hourglass False 'Cursor back to normal
End Sub
My Problem is that when the mailmerge is performed the word documents brings up a list of datasources to choose from....it should be automated. When I select the query everything works as expected.
Also my document does not have any data linked to it that is I have made it a 'Normal Document'. Any advice will be appreciated.
Thanks
Karv