Hi there,
I'm passing this thread on on behalf of a friend. He uses the code below to mail merge to Word. I'm told the code works perfectly but when the .dot template is opened the standard toolbar is not on view.
I know that the code from within word is
"CommandBars("Standard").Visible = True"
But would this still be the code when operating from Access and where in the sub should it appear?
On Error Resume Next
Dim db As DAO.Database
Dim objWord As Word.Application
Dim TemplateChoice As String
Dim strMyTemplatePath As String
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryCustomerInvoice"
DoCmd.SetWarnings True
Set db = CurrentDb()
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
objWord.Visible = True
'Code here to allow choice of Template
strMyTemplatePath = "C:\Invoice.dot"
objWord.Documents.Add Template:=strMyTemplatePath, NewTemplate:=False
objWord.ActiveDocument.MailMerge.OpenDataSource _
Name:=db.Name, _
LinkToSource:=True, _
Connection:="TABLE tblInvoice", _
SQLStatement:="Select * from [tblInvoice]"
objWord.ActiveDocument.MailMerge.Execute
Thanks
I'm passing this thread on on behalf of a friend. He uses the code below to mail merge to Word. I'm told the code works perfectly but when the .dot template is opened the standard toolbar is not on view.
I know that the code from within word is
"CommandBars("Standard").Visible = True"
But would this still be the code when operating from Access and where in the sub should it appear?
On Error Resume Next
Dim db As DAO.Database
Dim objWord As Word.Application
Dim TemplateChoice As String
Dim strMyTemplatePath As String
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryCustomerInvoice"
DoCmd.SetWarnings True
Set db = CurrentDb()
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
objWord.Visible = True
'Code here to allow choice of Template
strMyTemplatePath = "C:\Invoice.dot"
objWord.Documents.Add Template:=strMyTemplatePath, NewTemplate:=False
objWord.ActiveDocument.MailMerge.OpenDataSource _
Name:=db.Name, _
LinkToSource:=True, _
Connection:="TABLE tblInvoice", _
SQLStatement:="Select * from [tblInvoice]"
objWord.ActiveDocument.MailMerge.Execute
Thanks