populate word template from access

S

Sam

Hi All, I am trying to populate word template with current record in access.
Here is what I have so far. But it doesnt work. I have created a Button
"Export to Work" on Access Form which is connected to the database.

Private Sub ExportWord_Click()

Dim wdApp As Object
Dim doc As Object
On Error Resume Next
Set wdApp = GetObject("C:\My Documents\Address.dotx", "Word.Application")

If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Dim FName As String

sWdFileName = Application.GetOpenFilename(, , , , False)
'Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

On Error Resume Next
Set doc = wdApp.Documents.Open(sWdFileName)

With wdApp
.Variables("Address").Result = Me.Address
.Variables("City").Result = Me.City
.Variables("State").Result = Me.State
End With
wdApp.ActiveDocument.Fields.Update

FName = "C:\My Documents\" _
& "Address" & ".doc"

wdApp.ActiveDocument.SaveAs FileName:=FName

wdApp.Visible = True

Set doc = Nothing
Set wdApp = Nothing
wApp.Quit

End Sub

Thanks in advance
 
M

Mike Painter

I can't help much but unless there is something in teh Word Doc that has
some unigue formatting, recreating it in Access and printing it as a report
is trivial.
I've even used Access to print business cards.
 
B

Barry A&P

Sam
because i have no idea what im doing i get things done in odd ways.. you
could create a query in access that has all the data you want to export to
word then do a Mail Merge in word and use the query as a datasource?? kinda
3rd grade but i do it..

My two cents

Barry
 
A

Albert D. Kallal

I have a nice working sample that does a merge of the current record to
word.

The sample I have can be found here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

What is nice/interesting about my sample is that is specially designed to
enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with
great ease.

Make sure you read the instructions from above, and you should eventually
get to the following page
http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html


Note that the merge can also use a query, and thus you don't have to merge
just "one" record..

After the merge occurs, you get a plain document WITHOUT any merge fields,
and this allows the end user to save, edit, or even email the document
(since the merge fields are gone after the merge occurs).

Give the above a try....
 

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