populate word docs/templates from Access..

N

nycdon

Hi,
Can anyone point me to some basic instructions/samples on using vba to pass
fields from Access 2002 to Word 2002 templates?
I'm basically wanting to format/print a word doc from Access, with 5 or so
of the current record's data fields being passed to Word.
Thanks,
Don
 
S

Steve Commisso

OK, first thing you need to do is create a Word Template with mail merge
fields for the fields you want to pull from Access. Secondly, create a query
or table that contains the data you want to push over to word. Thirdly,
here's the VBA script you need to automate a mailmerge into Word from Access:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge doc>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="<QUERY <qryName> or TABLE <tblName>", _
SQLStatement:="Select * from [<qryName or tblName>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
 
N

nycdon

Thanks Steve! Very much appreciated.
Don

Steve Commisso said:
OK, first thing you need to do is create a Word Template with mail merge
fields for the fields you want to pull from Access. Secondly, create a query
or table that contains the data you want to push over to word. Thirdly,
here's the VBA script you need to automate a mailmerge into Word from Access:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge doc>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="<QUERY <qryName> or TABLE <tblName>", _
SQLStatement:="Select * from [<qryName or tblName>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
--
Steve Commisso
Consultant
Software Architects, Inc.


nycdon said:
Hi,
Can anyone point me to some basic instructions/samples on using vba to pass
fields from Access 2002 to Word 2002 templates?
I'm basically wanting to format/print a word doc from Access, with 5 or so
of the current record's data fields being passed to Word.
Thanks,
Don
 
D

Daisy

Hi,
Going a step further. How do you generate an automated mail merge to output
1 unique record from a query source that has many records? Is there a way
one can select the record of choice from access and then auto mail merge it
into word?

Any help is much appreciated :)


Steve Commisso said:
OK, first thing you need to do is create a Word Template with mail merge
fields for the fields you want to pull from Access. Secondly, create a query
or table that contains the data you want to push over to word. Thirdly,
here's the VBA script you need to automate a mailmerge into Word from Access:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge doc>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="<QUERY <qryName> or TABLE <tblName>", _
SQLStatement:="Select * from [<qryName or tblName>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
--
Steve Commisso
Consultant
Software Architects, Inc.


nycdon said:
Hi,
Can anyone point me to some basic instructions/samples on using vba to pass
fields from Access 2002 to Word 2002 templates?
I'm basically wanting to format/print a word doc from Access, with 5 or so
of the current record's data fields being passed to Word.
Thanks,
Don
 
F

fred

Hi Daisy, I need help with the exact same thing. I have several records that
show up on a subform query that I have to manually copy then paste into my
Word invoice. Basically, when I complete out the Work Order, the subform is
populated with all the individual jobs/tasks that are associated with the
work order. I would like to click a 'make invoice' button for the current
record. Maybe we can both get help with this. Thanks, Fred.

Daisy said:
Hi,
Going a step further. How do you generate an automated mail merge to output
1 unique record from a query source that has many records? Is there a way
one can select the record of choice from access and then auto mail merge it
into word?

Any help is much appreciated :)


Steve Commisso said:
OK, first thing you need to do is create a Word Template with mail merge
fields for the fields you want to pull from Access. Secondly, create a query
or table that contains the data you want to push over to word. Thirdly,
here's the VBA script you need to automate a mailmerge into Word from Access:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge doc>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="<QUERY <qryName> or TABLE <tblName>", _
SQLStatement:="Select * from [<qryName or tblName>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
--
Steve Commisso
Consultant
Software Architects, Inc.


nycdon said:
Hi,
Can anyone point me to some basic instructions/samples on using vba to pass
fields from Access 2002 to Word 2002 templates?
I'm basically wanting to format/print a word doc from Access, with 5 or so
of the current record's data fields being passed to Word.
Thanks,
Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top