ACCESS DATA TO MS WORD

G

Guest

I created a letter in MS word with insert field formula (to merge). On MS
access form design view I added a command button to open MS word application
on click. When I click the MS Word command button it open the letter I
created on the MS word but the data doesn’t merge. This is my code

Private Sub Command63_Click()
On Error GoTo Err_Command63_Click

Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Exit_Command63_Click:
Exit Sub

Err_Command63_Click:
MsgBox Err.Description
Resume Exit_Command63_Click

End Sub
 
S

Someone

Hi Rose

Your code below simply opens Word and makes it visible. You also need to
tell Access what to do with the data (i.e. what fields need to be merged to
what parts of the Word document). You must add bookmarks to the document
you want the data to be merged to. If you're not too sure how to do this,
just read the help in Word - it should be easy enough to understand (for a
change!)

The following is how you could code the data merge:

With objWord.ActiveDocument
.Bookmarks("FieldName1").Range.Text = Me!ValueInFieldName1.Value
.Bookmarks("FieldName2").Range.Text = Me!ValueInFieldName2.Value
.Bookmarks("FieldName3").Range.Text = Me!ValueInFieldName3.Value
.Bookmarks("DateField").Range.Text = Format(Me!DateField.Value, "dddd d
MMMM yyyy")
.Bookmarks("FieldName4").Range.Text = strField (you can use calculated
fields, for example)
End With

You just repeat the .Bookmarks line as appropriate to fill all fields.

You can also have the file automatically saved, such as:

objDoc.SaveAs FileName:=("C:\file.doc") -this is an exact location
--or--
objDoc.SaveAs FileName:=(strFileName) - you can assemble the location by
code and store it in a string

Does this give you the help you need to complete the merge?

Thanks
M
 

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