I have my mail merge working...however when my query result set returns more than one record the mail merge stops on the first record..how can i get it to do a merge for every record? I'm using bookmarks in my word document..Thans in advance.
Private Sub Command0_Click()
Dim strSql As String
On Error GoTo ErrorHandler
Set Appword = CreateObject("word.application")
strSql = "SELECT tblEvents.Event_Date, format(tblEvents.Event_BeginTime,""h:nn ampm"") & "" - "" & "
strSql = strSql & " format(tblEvents.Event_EndTime,""h:nn ampm"") AS Event_Time, tblEvents.Event_Location, "
strSql = strSql & " tblEvents.Event_Address, tblEvents.Event_City, tblEvents.Event_Zip, tblMedia.Media_Name, "
strSql = strSql & " tblMedia.Media_Address, tblMedia.Media_City, tblMedia.Media_Zip"
strSql = strSql & " FROM tblMedia INNER JOIN tblEvents ON tblMedia.Media_ID = tblEvents.Event_Media_Id"
strSql = strSql & " WHERE Event_Date Between " & "#" & Forms!frmMediaRelease!txtDateFrom & "#" & " and " & "#" & Forms!frmMediaRelease!txtDateTo & "#"
strSql = strSql & " ORDER BY Event_Date" & ";"
Set rstMerge = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
'Get an Application object so you can automate Word.
Set Appword = CreateObject("Word.Application")
With Appword
.Visible = True
.Documents.Open "K:\COMMON\DRV\Senior Events\Seniors\ROR Press Release.doc", , , True, "seniors" 'seniors is password for this doc
.ActiveDocument.Bookmarks("MediaName").SELECT
.selection.Text = rstMerge![Media_Name]
.ActiveDocument.Bookmarks("MediaAddress").SELECT
.selection.Text = rstMerge![Media_Address]
.ActiveDocument.Bookmarks("MediaCity").SELECT
.selection.Text = rstMerge![Media_City]
.ActiveDocument.Bookmarks("MediaZip").SELECT
.selection.Text = rstMerge![Media_Zip]
.ActiveDocument.Bookmarks("Location").SELECT
.selection.Text = rstMerge![Event_Location]
.ActiveDocument.Bookmarks("Location2").SELECT
.selection.Text = rstMerge![Event_Location]
.ActiveDocument.Bookmarks("City").SELECT
.selection.Text = rstMerge![Event_City]
.ActiveDocument.Bookmarks("LocationCity").SELECT
.selection.Text = rstMerge![Event_City]
.ActiveDocument.Bookmarks("LocationAddress").SELECT
.selection.Text = rstMerge![Event_Address]
.ActiveDocument.Bookmarks("LocationZip").SELECT
.selection.Text = rstMerge![Event_Zip]
.ActiveDocument.Bookmarks("Date").SELECT
.selection.Text = rstMerge![Event_Date]
.ActiveDocument.Bookmarks("Time").SELECT
.selection.Text = rstMerge![Event_Time]
End With
Set Appword = Nothing
rstMerge.Close
CurrentDb.Close
Exit Sub 'Exit sub if no errors
ErrorHandler:
Appword.Quit
MsgBox Err.Description
End Sub
________
Lightning
Private Sub Command0_Click()
Dim strSql As String
On Error GoTo ErrorHandler
Set Appword = CreateObject("word.application")
strSql = "SELECT tblEvents.Event_Date, format(tblEvents.Event_BeginTime,""h:nn ampm"") & "" - "" & "
strSql = strSql & " format(tblEvents.Event_EndTime,""h:nn ampm"") AS Event_Time, tblEvents.Event_Location, "
strSql = strSql & " tblEvents.Event_Address, tblEvents.Event_City, tblEvents.Event_Zip, tblMedia.Media_Name, "
strSql = strSql & " tblMedia.Media_Address, tblMedia.Media_City, tblMedia.Media_Zip"
strSql = strSql & " FROM tblMedia INNER JOIN tblEvents ON tblMedia.Media_ID = tblEvents.Event_Media_Id"
strSql = strSql & " WHERE Event_Date Between " & "#" & Forms!frmMediaRelease!txtDateFrom & "#" & " and " & "#" & Forms!frmMediaRelease!txtDateTo & "#"
strSql = strSql & " ORDER BY Event_Date" & ";"
Set rstMerge = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
'Get an Application object so you can automate Word.
Set Appword = CreateObject("Word.Application")
With Appword
.Visible = True
.Documents.Open "K:\COMMON\DRV\Senior Events\Seniors\ROR Press Release.doc", , , True, "seniors" 'seniors is password for this doc
.ActiveDocument.Bookmarks("MediaName").SELECT
.selection.Text = rstMerge![Media_Name]
.ActiveDocument.Bookmarks("MediaAddress").SELECT
.selection.Text = rstMerge![Media_Address]
.ActiveDocument.Bookmarks("MediaCity").SELECT
.selection.Text = rstMerge![Media_City]
.ActiveDocument.Bookmarks("MediaZip").SELECT
.selection.Text = rstMerge![Media_Zip]
.ActiveDocument.Bookmarks("Location").SELECT
.selection.Text = rstMerge![Event_Location]
.ActiveDocument.Bookmarks("Location2").SELECT
.selection.Text = rstMerge![Event_Location]
.ActiveDocument.Bookmarks("City").SELECT
.selection.Text = rstMerge![Event_City]
.ActiveDocument.Bookmarks("LocationCity").SELECT
.selection.Text = rstMerge![Event_City]
.ActiveDocument.Bookmarks("LocationAddress").SELECT
.selection.Text = rstMerge![Event_Address]
.ActiveDocument.Bookmarks("LocationZip").SELECT
.selection.Text = rstMerge![Event_Zip]
.ActiveDocument.Bookmarks("Date").SELECT
.selection.Text = rstMerge![Event_Date]
.ActiveDocument.Bookmarks("Time").SELECT
.selection.Text = rstMerge![Event_Time]
End With
Set Appword = Nothing
rstMerge.Close
CurrentDb.Close
Exit Sub 'Exit sub if no errors
ErrorHandler:
Appword.Quit
MsgBox Err.Description
End Sub
________
Lightning
Last edited: