Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
PC User PC User is offline
external usenet poster
 
Posts: 6
Default Mail merge question

Maybe this might help.

How to send the current record to Word 2000 with automation

'http://support.microsoft.com/kb/q210271/

Private Sub MergeButton_Click()

On Error GoTo MergeButton_Err

Dim objWord As Word.Application

'Copy the Photo control on the Employees form.
DoCmd.GoToControl "Photo"
DoCmd.RunCommand acCmdCopy

'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\MyMerge.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("First").Select
.Selection.Text = (CStr(Forms!Employees!FirstName))
.ActiveDocument.Bookmarks("Last").Select
.Selection.Text = (CStr(Forms!Employees!LastName))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Forms!Employees!Address))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Forms!Employees!City))
.ActiveDocument.Bookmarks("Region").Select
.Selection.Text = (CStr(Forms!Employees!Region))
.ActiveDocument.Bookmarks("PostalCode").Select
.Selection.Text = (CStr(Forms!Employees!PostalCode))
.ActiveDocument.Bookmarks("Greeting").Select
.Selection.Text = (CStr(Forms!Employees!FirstName))

'Paste the photo.
.ActiveDocument.Bookmarks("Photo").Select
.Selection.Paste
End With

'Print the document in the foreground so Microsoft Word will not
close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next

'If the Photo field is empty.
ElseIf Err.Number = 2046 Then
MsgBox "Please add a photo to this record and try again."
Else
MsgBox Err.Number & vbCr & Err.Description
End If

Exit Sub
End Sub

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail merge question Erika Mailmerge 1 August 15th 07 09:45 PM
Mail merge question Suki Mailmerge 5 February 19th 07 03:20 PM
Mail Merge Question Jim McColl Microsoft Word Help 9 July 23rd 06 04:30 AM
Mail Merge Question Kathy New Users 1 July 9th 05 06:03 AM
Mail Merge question TDRK Microsoft Word Help 4 April 7th 05 03:35 AM


All times are GMT +1. The time now is 12:33 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"