Group:  Microsoft Word ยป microsoft.public.word.vba.customization
Thread: Inserting data from an ACCESS form into a bookmark in WORD

Geek News

Inserting data from an ACCESS form into a bookmark in WORD
"Doctorjones_md" <xxxDoctorjones_mdxxx[ at ]xxxyahoo.com> 5/18/2007 3:56:52 PM
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


Re: Inserting data from an ACCESS form into a bookmark in WORD
"Len Robichaud" <len.robichaud[ at ]rqwproserv.com> 6/7/2007 2:01:49 PM
First, Create a Command Button on your form
Then in the OnClick event, choose Code Builder and paste the following Sub

*************************************
Sub PopWordTemplate()
On Error GoTo PopWordTemplate_Error

Dim strTemplateFolder as string
Dim strTemplateFileName as string
Dim strTemplatePath As String
Dim objWord As Word.Application
Dim docWord As Word.Document

'Open Word
On Error Resume Next
'If Word is already Open
Set objWord = GetObject(, "Word.Application")
'If Word is not Open, Open it
If Err.Number <> 0 Then 'Start Word
Set objWord = CreateObject("Word.Application")
End If

On Error GoTo PopWordTemplate_Error

'The following assumes the word template is in the same folder as your
Database
'If it is somewhere else replace the following with strTemplateFolder =
"your path here" (the quotes are required)
strTemplateFolder = Application.CurrentProject.Path

strTemplateFileName = "\"& "your Template Name" &".dot"
strTemplatePath = strTemplateFolder & strTemplateFileName

'Opens the template as a new doc and allows it to be viewed
objWord.Documents.Add Template:=strTemplateFile, NewTemplate:=False
objWord.Visible = True

With objWord
' Find a bookmark and replace it with something from your Open Form
.ActiveDocument.Bookmarks("MyBookmark1").Select
.Selection.Text = me!SomeFieldOnMyForm1
.ActiveDocument.Bookmarks("MyBookmark2").Select
.Selection.Text = me!SomeFieldOnMyForm2
End With

Exit Sub

PopWordTemplate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
PopWordTemplate of Module basAutomation"
End Sub
*********************************
Len Robichaud

"Doctorjones_md" <xxxDoctorjones_mdxxx[ at ]xxxyahoo.com> wrote in message
news:%23akCoUWmHHA.4624[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
>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
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net