Magpies007
Programmer
- Jul 14, 2008
- 1
Hi all I am new to this forum please bear with me. I am trying to write some code for a command button in my access application to merge an existing letter with a a query . The code is this
Function MergeIt()
Dim objWord As Word.Application
Set objWord = GetObject("C:\Documents and Settings\Rob\My Documents\Whitsundays\Operational Works\Template - Letter On maintenance Defects.doc", "Word.Application")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Operational Work database.
objWord.MailMerge.OpenDataSource _
Name = "C:\Documents and Settings\Rob\My Documents " & _
"Whitsundays\Operational Works\Ops Work Database\Operational Works.mdb", _
LinkToSource:=True, _
Connection:="QUERY Merge details Defects", _
SQLStatement:="SELECT * FROM [merge details defects]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
I get a compile error "Method or Data member not found", on the line "objWord.MailMerge.OpenDataSource". with .MailMerge highlighted. I am at a loss as to why. Please can anyone help.Thank in advance
Function MergeIt()
Dim objWord As Word.Application
Set objWord = GetObject("C:\Documents and Settings\Rob\My Documents\Whitsundays\Operational Works\Template - Letter On maintenance Defects.doc", "Word.Application")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Operational Work database.
objWord.MailMerge.OpenDataSource _
Name = "C:\Documents and Settings\Rob\My Documents " & _
"Whitsundays\Operational Works\Ops Work Database\Operational Works.mdb", _
LinkToSource:=True, _
Connection:="QUERY Merge details Defects", _
SQLStatement:="SELECT * FROM [merge details defects]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
I get a compile error "Method or Data member not found", on the line "objWord.MailMerge.OpenDataSource". with .MailMerge highlighted. I am at a loss as to why. Please can anyone help.Thank in advance