Output to Word - merge single record

D

Dadio

Hello

On my Access database form I have a command button which opens a Word mail
merge document in which I have created a number of fields (Title, FirstName,
LastName, Address1 etc.)

I would like to be able to populate the Word document with the contents of
the currently selected Access record so that when I press the button in
Access, Word opens with the appropriate fields populated and ready to print.
It is a "one off" event which I will use, typically, to print a single
letter or invoice which is more easily edited in Word.

My code at the moment is:
-------
Private Sub StartWord_Click()
On Error GoTo Err_StartWord_Click

Dim LWordDoc As String
Dim oApp As Object

'Path to the word document
LWordDoc = "m:\database\poolshop\Invoice new.doc"

If Dir(LWordDoc) = "" Then
MsgBox "Document not found."

Else
'Create an instance of MS Word

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

'Open the Document
oApp.Documents.Open FileName:=LWordDoc
End If

Exit_StartWord_Click:
Exit Sub

Err_StartWord_Click:
MsgBox Err.Description
Resume Exit_StartWord_Click

End Sub
-------

But at the moment it does not automatically populate Word with anything, or
at least, by default, I see the contents of the first record. What I want is
to see, in my Word fields, the data from the current record. I can use the
normal mail merge search facility in Word to do a query and find the right
record but that is clumsy and I know you can do better.

I do not want to sound arrogant (be kind to me) but I do quite like the bit
of code that I have used (copied from elsewhere) and rather hope that all I
need to do is add a "current.record" type of command to it somewhere to get
the result that I need.

Thank you for your help, keep it simple.

Les
 
D

Dadio

Dear Albert

You are a star. I confess (as you will have noticed) to shameless cross
posting (here and comp.database.ms-access) and you took the trouble to
respond in both arenas.

The code you provided and the supporting documentation is just fabulous mega
thanks and congratulations on producing something that works brilliantly and
is explained so clearly that I was able to follow your instructions and get
everything working straight away without any problems whatsoever. This
solution to what must be an everyday problem should be shouted from the
rooftops.

Now go and put your feet up with a warm inner glow knowing that you have
helped someone who is very grateful.

Sincerely

Les
 

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