Mail Merge Update

A

AccessARS

I have a mail merge document that is linked to an Access database table. A
VBA procedure runs from Access that updates that table thereafter opens the
linked mail merge document. My problem is that when I open the mail merged
document through the Access VBA procedure it does not update the record
in the merged doc but when I open the same document manually, first it
prompts me that it will run a SQL statement from the Access table to merge
that data and when I click OK it shows the new record. (keep in mind that
when the same mail merge document is opened through the VBA procedure it does
not prompt me for
anything instead opens the document with the last existing record).

Is there a way that I can code the Word document to somehow refresh the
merged records on open since it does not do so when I open it through my
procedure?

Any assistance would be greatly appreciated.
 
D

Doug Robbins - Word MVP

I would help if you showed the procedure that you are running. Copy and
paste the code into a message that you post back here.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

AccessARS

Here it is and thank you...

Private Sub cmd_Informal_Click()
Dim qrf As querydef
Dim Name As String
Dim db As Database
Dim rst As Recordset

If IsNull(Me!Name.Value) Then
MsgBox "Please enter Full Name to continue.", vbExclamation, "MISSING
FULL NAME"
Me!Name.SetFocus
Exit Sub
End If

Name = Me!Name.Value



If Name = Null Then
MsgBox "Please enter Agent name.", vbExclamation, "MISSING AGENT NAME"
Exit Sub
End If

Set db = CurrentDb

DoCmd.SetWarnings False

DoCmd.RunSQL "delete from temp_Informal"

Set qrf = db.QueryDefs("qry_Informal")
qrf.Parameters("name") = Name
qrf.Execute
Set qrf = Nothing

DoCmd.SetWarnings True

Set rst = db.OpenRecordset("temp_Informal")

With rst
If .EOF = True Then
MsgBox "There are no records available for:" & vbCrLf & Me!Name &
vbCrLf & "Please check the spelling of the name.", vbExclamation, "NAME DOES
NOT EXIST"
Me!Name.SetFocus
.Close
Exit Sub
Else
DoCmd.SetWarnings False

DoCmd.RunSQL "delete from temp_Occurrences"

Set qrf = db.QueryDefs("qryComplete Occurrence History")
qrf.Parameters("name") = Name
qrf.Execute
Set qrf = Nothing

DoCmd.SetWarnings True


Set rst = db.OpenRecordset("temp_Occurrences")

If .EOF = True Then
MsgBox "There are no occurrences to report for" & Name,
vbExclamation, "NO OCCURRENCES"
Me!Name.SetFocus
.Close
Exit Sub
Else
Dim Idoc
Set Idoc = CreateObject("Word.Application")
Idoc.Visible = True
Idoc.Documents.Open
Filename:="\\holnt01\public\Projects-Hollywood\S3\Databases\Working\Attendance\Informal Merge.doc"

DoCmd.OutputTo acOutputReport, "Occurrence_History",
acFormatRTF,
"\\holnt01\public\Projects-Hollywood\S3\Databases\Working\Attendance\OccurrenceHistory.doc", True
.Close

End If
End If

End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top