Mail Merge Problem

Motorhead

Registered User.
Local time
Today, 23:19
Joined
Feb 19, 2002
Messages
11
Hello!
I got the following code:

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("selectet path", "Word.Document")
' Make Word Visible.
objWord.Application.Visible = True
' Set the Mail Merge data Source.
objWord.MailMerge.OpenDataSource Name:="current db", LinkToSource:=True, Connection:="TABLE tests", SQLStatement:="Select * from [tests]"
' Execute the Mail Merge.
objWord.MailMerge.Execute
End Function

'(hope that it is readable)'

This code works perfectly but in the document he puts after one merged record a section brake(next page) but I want a page break.
Also I've got some OLE objects in the selected table wich are MS-Word Documents. In the document I only get to see is: Long binary or text value, but not the MS-Word document in the selected table.

Could Anyone help me with this

Greetz,

Martijn ;p
 
I got the same code from Microsoft and I also have the same problem you have with the OLE objects. I am specifically working with images and the way I found to solve it is to step on the image on a form, copy it and then paste it to a word doc. I havent finished yet a way to mix that with the mail merge.
Just in case, here is how it works:
You have to add bookmarks to you word doc and then call the doc from a form:

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"
' Remove the following comment in Microsoft Access 97.
' DoCmd.RunCommand acCmdCopy
' Remove the following comment in Microsoft Access 7.0.
' DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70
' Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")
With objWord
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("c:\my documents\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 97
' 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 97 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

this is just part of the solution.
The rest is not ready yet
 
Try setting up a selection and use the Insert File function:

Dim wrdSelection As Word.Selection
Set wrdSelection = wrdApp.Selection()
wrdSelection.InsertFile FileName
 

Users who are viewing this thread

Back
Top Bottom