Hi all, I've been going through the threads on the Mergit() function to run a Word mailmerge out of Access, and I've hit a roadblock.
The first problem I had was discussed in this thread: http://www.thescripts.com/forum/thre...rd+access.html
So as instructed, I added a reference to Microsoft Word. On the bright side, at least I'm getting a different error than I was before (but I still can't get it to work)
Here's the code (I haven't written the error handling part yet)
The error I'm getting is: 91 - Object Variable or With Block Variable not set. (The debugger highlights the "Set objDoc" line.) As far as I can tell I /have/ set the object variable, and I /have/ initialized the with...end with bit. Or not? I'm pretty new at this, so there's a good chance I'm missing something.
Thanks for any insight you can provide!
The first problem I had was discussed in this thread: http://www.thescripts.com/forum/thre...rd+access.html
So as instructed, I added a reference to Microsoft Word. On the bright side, at least I'm getting a different error than I was before (but I still can't get it to work)
Here's the code (I haven't written the error handling part yet)
Code:
Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim strFilename As String
Dim strQueryName As String
Dim strDBPath As String
'DocFileName is a field that users choose which document they want to merge to
strFilename = "c:\DocumentLibary\" & Me.DocFileName
strQueryName = "qryIntendedContractMergeSource"
strDBPath = "c:\ContractModule.mdb"
Set objDoc = objWord.Documents.Open(strFilename)
objWord.Visible = True
With objDoc.MailMerge
objDoc.MailMerge.OpenDataSource Name:=strDBPath, _ LinktoSource:=True, Connection:="QUERY" & strQueryName, _ SQLStatement:="Select * from " & strQueryName
.destination = wdSendToNewDocument
.Execute
objWord.ActiveDocument.PrintOut False
objWord.ActiveDocument.Close wdDoNotSaveChanges
End With
Thanks for any insight you can provide!
Comment