Inserting data from an ACCESS form into a bookmark in WORD

D

Doctorjones_md

I have the following code (which opens a NEW Word document and prints the
data from my ACCESS form) -- I need code that will open a specified WORD
template and insert the ACCESS data into a specific bookmark. I'm sure this
is a simple process, but I'm somewhat frazzled (at this point) and have
settled on this option over several previous suggestions. Here's the code I
need to modify:
==================================
'The following code outputs the Print Detail data to a NEW Word document

'On Error GoTo Err_Command83_Click

'Dim stDocName As String
'Dim MyForm As Form

'stDocName = "PrintDetails"
'Set MyForm = Screen.ActiveForm
'DoCmd.SelectObject acForm, stDocName, True
'DoCmd.PrintOut
'DoCmd.SelectObject acForm, MyForm.Name, False

'Exit_Command83_Click:
'Exit Sub

'Err_Command83_Click:
'MsgBox Err.Description
'Resume Exit_Command83_Click
 
S

Sergey Poberezovskiy

I think you will need to play with Automation here: first print out your form
to a new document, then open Word (Automation) object, open your newly
created output, select it all and copy to Clipboard; then open your template,
locate the bookmark and paste from the Clipboard. After that you can close
the original output and delete the file (some housekeeping)
 
P

Paul Shapiro

This code opens a new document from a specified template. The oWord object
has already been initialized to Word.Application.
Set oDoc = oWord.Documents.Add(Template:=strTemplate)

Here is code that replaces a named bookmark with text:
Function ReplaceBookmark( _
oDoc As Word.Document, _
strBookmarkName As String, _
strReplacementText As String) As Boolean
'Replace all occurrences of the bookmark with the replacement text
With oDoc.Bookmarks
If .Exists(strBookmarkName) Then
.Item(strBookmarkName).Range.Text = strReplacementText
ReplaceBookmark = True
End If
End With
End Function
 

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