Little Mail Merge Question

dsomers

Registered User.
Local time
Today, 05:52
Joined
Nov 13, 2003
Messages
131
Hello! I'm doing a mail merge with a Word document and here's the code that I have (got it off the Microsoft website after doing a search here on the forums):

Code:
Private Function MergeIt()

    Dim objWord As Word.Document
    Set objWord = GetObject("G:\Past Due Notice - 5th.doc", "Word.Document")
    
    ' Make Word invisible
    objWord.Application.Visible = False
    
    ' Set the mail merge data source as the database
    objWord.MailMerge.OpenDataSource Name:="G:\temp5 _
\FPMLLCNEW_SB.mdb", LinkToSource:=True, _ 
Connection:="TABLE tblLateNotice", SQLStatement:="Select * from [tblLateNotice]"
    
    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

When I try to call the function to see what it'll do, it gives me a compile error saying User-defined type not defined and it highlights the 'Dim objWord As Word.Document'.

Why am I getting this?

Thanks!
David Somers
 
Nevermind, I figured it out. I had to add the Word Object Library to my references list.

Later,
David Somers
 
If you install your database on an earlier version of Access than you are using you will get the same error, and each time you transfer it you will have to add the Current Word Object library.

2k is 9
XP is 10
03 is 11
07 is 12
 

Users who are viewing this thread

Back
Top Bottom