View Full Version : Merging access data into Word 2003


jawed
08-29-2007, 01:28 AM
Hi,
how do i get the current record form access 2003 to merge the data into word 2003 template that I created.

The code I'm using is :-

Private Sub Command313_Click()
Dim oApp As Object
Dim doc As Object
Dim strDocName As String

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

strDocName = "K:\Supported Living Services\database\DB-Personnel.dot"
Set doc = oApp.Documents.Open(strDocName)


doc.FormFields("Title").Result = Forms!Personal!Title
doc.FormFields("fristname").Result = Forms!Personal!firstname

Set doc = oApp.Documents.Add(strDocName)

End Sub


I'm using 2 fields here but will be adding a lot more once I got it working.


Thanks inadvance

ps (only a novice at access)

Dennisk
08-29-2007, 03:32 AM
what to mean by current? if you have a form displaying a record and the above code is attatched to a button on the form then that should work.

jawed
08-29-2007, 03:39 AM
Hi,
Thanks for your response.

I have about 2000 records, I idea is that which were record that i'm in I want to click on the button and then that record is merged into a word template.

I get the following error when i click on the button.

Run-time error '5941'
The requested member of the collection does not exit.

I click on debug and the follwoing line is highlighted

doc.FormFields("Title").Result = Forms!Personal!Title


Thanks

jawed
08-29-2007, 03:41 AM
Hi,
Thanks for your response.

I have about 2000 records, I idea is that which were record that i'm in I want to click on the button and then that record is merged into a word template.

I get the following error when i click on the button.

Run-time error '5941'
The requested member of the collection does not exit.

I click on debug and the follwoing line is highlighted

doc.FormFields("Title").Result = Forms!Personal!Title


Thanks

Pat Hartman
08-29-2007, 06:58 PM
Either the bookmark doesn't exist or the form field doesn't exist. Make sure there are no typos and make sure the Personal form is open when this code runs.