How to set up a word doc on templet

wlgzhang

Registered User.
Local time
Today, 16:38
Joined
Aug 16, 2004
Messages
19
Hello everyone,
I need help for how to set up a word doc on templet so that I can export report or pull data from my Access database through MailMerge to the specified word doc. I can open an empty word doc from Access by using vba code, however, I could not pull the data to the word doc and I got run time erro. Can anybody gives me helps.
the code is at the following:
DoCmd.Hourglass True
If CreateWordObj() Then
With gobjWord
.Visible = True
.Documents.Open "H:\NCASchedule\Applicantletter.doc"
DoEvents
With gobjWord.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With
.ActiveDocument.PrintPreview 'Preview
.Visible = True
End With
End If

Thank you

Wei Zhang
 
I hope this helps.
-------------------------------------------------------

Dim objword As New Word.Application
Dim objdoc As Word.Document


DoCmd.OpenQuery "qrxDelMailMergeItems"
DoCmd.OpenQuery "qrxAddMailMergeItems"

objword.Application.Visible = True
Set objdoc = objword.Documents.open("C:\Template.dot")
objword.Visible = True

objdoc.MailMerge.OpenDataSource Name:="C:\database.mdb",_
linktoSource:=True, passworddocument:="", writepassworddocument:="",_
writepasswordtemplate:="", Connection:="TABLE tblname",_
sqlstatement:="Select * FROM [tblname]", openexclusive:=False

objdoc.MailMerge.Execute


Set objword = Nothing
Set objdoc = Nothing
 
Sorry I added to many lines.

here it is again.
-------------------------------------------------
Dim objword As New Word.Application
Dim objdoc As Word.Document


objword.Application.Visible = True
Set objdoc = objword.Documents.open("C:\Template.dot")
objword.Visible = True

objdoc.MailMerge.OpenDataSource Name:="C:\database.mdb",_
linktoSource:=True, passworddocument:="", writepassworddocument:="",_
writepasswordtemplate:="", Connection:="TABLE tblname",_
sqlstatement:="Select * FROM [tblname]", openexclusive:=False

objdoc.MailMerge.Execute


Set objword = Nothing
Set objdoc = Nothing
 

Users who are viewing this thread

Back
Top Bottom