I have a db whit a query, now when a user is clicking on a button in a form there most be print a number of letters whit some data of the query.
I have now the following code:
Public Sub MergeToWord(strDocName As String, MyQuery As String)
Dim objApp As Object
'Change cursor to hourglass
'Open Mailmerge Document
Set objApp = CreateObject("Word.Application")
.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
'print and close Document
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges 'Avoid Saving over your template
.Quit SaveChanges:=wdDoNotSaveChanges 'close all documents
Set objApp = Nothing
Select Case Err.Number
DoCmd.Hourglass False 'Cursor back to normal
the word file has all the correct merg reference and no connection.
only when i am running the code it will stop in word and ask me to select the correct table/query. How ever i give the query in the line: Connection:="QUERY " & MyQuery
I have try moste options under ActiveDocument.MailMerge.OpenDataSource but don't get it to work. Does someone now how to get round this message form word?