Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word.
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("CompanyName").Select
.Selection.Text = (CStr(Forms!forCustomerDetails2!CompanyName))
Me.forSiteName.Form.SetFocus
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("SiteName").Select
.Selection.Text = (CStr(Forms!forSiteName!SiteName))
.ActiveDocument.Bookmarks("cboDesignation").Select
.Selection.Text = (CStr(Forms!forSiteName!cboDesignation))
.ActiveDocument.Bookmarks("SiteAddress1").Select
.Selection.Text = (CStr(Forms!forSiteName!SiteAddress1))
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Supplier").Select
.Selection.Text = (CStr(Forms!forJobTracking!Supplier))
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Forms!forJobTracking!JobNo))
.ActiveDocument.Bookmarks("Description").Select
.Selection.Text = (CStr(Forms!forJobTracking!Description))
' Me.forProject2.Form.SetFocus
'Me.forProject2.SetFocus
'Me.forProject2!DateofComments.SetFocus
'
'
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("DateofComment").Select
.Selection.Text = (CStr(Forms!forProject2!DateofComment))
.ActiveDocument.Bookmarks("Comments").Select
.Selection.Text = (CStr(Forms!forProject2!Comments))
.ActiveDocument.Bookmarks("Action").Select
.Selection.Text = (CStr(Forms!forProject2!Action))
.ActiveDocument.Bookmarks("ActionByDate").Select
.Selection.Text = (CStr(Forms!forProject2!ActionByDate))
.ActiveDocument.Bookmarks("ByWhom").Select
.Selection.Text = (CStr(Forms!forProject2!ByWhom))
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
End If
Exit Sub
End Sub