Help! I think I'm stuck:
I was testing a function per Q159328 - ACC: Example: Mail Merge a MS Access 97 Query with Word 97 document.
I keep getting this error: MS Run-time error '5273':
The document name or path is not valid. But I know I have the correct path.
This is my code:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("J:\shared\Layout\WorkingFolder\LayoutMaster.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the MACH_4 database.
objWord.MailMerge.OpenDataSource _
Name:="J:\shared\Layout" & _
"WorkingFolder\MACH_4.mdb", _
LinkToSource:=True, _
Connection:="TABLE Layout", _
SQLStatement:="Select * from [Layout]"
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
End Function
Note1: The error was pointing to the lines in bold/italic and the Debug window was displaying the wrong database name.
Note2: Also want to point out that the actual data source is based on 3 parameter query. In case that might make a difference.
Thanks!
I was testing a function per Q159328 - ACC: Example: Mail Merge a MS Access 97 Query with Word 97 document.
I keep getting this error: MS Run-time error '5273':
The document name or path is not valid. But I know I have the correct path.
This is my code:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("J:\shared\Layout\WorkingFolder\LayoutMaster.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the MACH_4 database.
objWord.MailMerge.OpenDataSource _
Name:="J:\shared\Layout" & _
"WorkingFolder\MACH_4.mdb", _
LinkToSource:=True, _
Connection:="TABLE Layout", _
SQLStatement:="Select * from [Layout]"
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
End Function
Note1: The error was pointing to the lines in bold/italic and the Debug window was displaying the wrong database name.
Note2: Also want to point out that the actual data source is based on 3 parameter query. In case that might make a difference.
Thanks!