A
A. Smart
I have a button that when clicked merges fields from a form to Bookmarks in a
mailmerge document ... no problem!!!!
How do I do the same with a query!! I want a query that is created on the
same form to be merged to a bookmark in the same document.
Please help I'm at my wits end. Thanx in advance.
My code goes like this:
Private Sub Merge_Click()
On Error GoTo Err_Merge_Click
Dim WordTemplate As String
Dim strFullName As String
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
WordTemplate = Application.CurrentProject.Path & "\Blank Template.dot"
strFullName = Me.Job_Title
' Start Word with Mail Merge template
With objWord
.Visible = True
.Documents.Add (WordTemplate)
.Caption = strFullName
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Me.Job_No))
.ActiveDocument.Bookmarks("JobTitle").Select
.Selection.Text = (CStr(Me.Job_Title))
.ActiveDocument.Bookmarks("WorkStation").Select
.Selection.Text = (CStr(Me.Work_Station))
.ActiveDocument.Bookmarks("IssueNo").Select
.Selection.Text = (CStr(Me.Issue_No))
.ActiveDocument.Bookmarks("IssueDate").Select
.Selection.Text = (CStr(Me.Issue_Date))
.Activate
End With
Exit_Merge_Click:
Set objWord = Nothing
Exit Sub
Err_Merge_Click:
MsgBox Err.Number & ": " & Err.Description, vbInformation, "Error"
Resume Exit_Merge_Click
End Sub
mailmerge document ... no problem!!!!
How do I do the same with a query!! I want a query that is created on the
same form to be merged to a bookmark in the same document.
Please help I'm at my wits end. Thanx in advance.
My code goes like this:
Private Sub Merge_Click()
On Error GoTo Err_Merge_Click
Dim WordTemplate As String
Dim strFullName As String
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
WordTemplate = Application.CurrentProject.Path & "\Blank Template.dot"
strFullName = Me.Job_Title
' Start Word with Mail Merge template
With objWord
.Visible = True
.Documents.Add (WordTemplate)
.Caption = strFullName
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Me.Job_No))
.ActiveDocument.Bookmarks("JobTitle").Select
.Selection.Text = (CStr(Me.Job_Title))
.ActiveDocument.Bookmarks("WorkStation").Select
.Selection.Text = (CStr(Me.Work_Station))
.ActiveDocument.Bookmarks("IssueNo").Select
.Selection.Text = (CStr(Me.Issue_No))
.ActiveDocument.Bookmarks("IssueDate").Select
.Selection.Text = (CStr(Me.Issue_Date))
.Activate
End With
Exit_Merge_Click:
Set objWord = Nothing
Exit Sub
Err_Merge_Click:
MsgBox Err.Number & ": " & Err.Description, vbInformation, "Error"
Resume Exit_Merge_Click
End Sub