yddadsjd95
asked on
Receive error # 5852 when creating Word mail merge from MS Access
Happy New Year to all, I am attempting to create a mail merge from
Access using an Access Query as my data source. The VBA code takes me
to Word from Access and opens my merge letter, but I get the following
error after Word has loaded:
Error #5852
Requested Object not available
The following is the VBA code that the VBA debugger gives me after the
error.
.Destination = wdSendTonewDocument
And this is the code that I use:
Private Sub btnMailMerge_Click()
' On Error GoTo Err_btnMailMerge_Click
Dim strMergeLetterName as String
' Turn Hourglass on
DoCmd.Hourglass True
' Attempt to create a Word object
If CreateWordObj() Then
' If Word object created
With gobjWord
' Make Word Visible
.Visible = True
strMergeLetterName = "\"
strMergeLetterName = strMergeLetterName & txtMergeLetterName
' Open document
.Documents.Open CurrentProject.Path & txtMergeLetterName
' Give the document time to open
DoEvents
'Use the mailmerge method of the document to perform a
mail merge
With gobjWord.ActiveDocument.Ma ilMerge
.Destination = wdSendTonewDocument
.SuppressBlankLines = True
.Execute
End With
' Send results of the Mailmerge to the print preview window
.ActiveDocument.PrintPrevi ew ' Preview
' Make Word visible
.Visible = True
End With
End If
'Exit_btnMailMerge_Click:
' ' Turn hourglass off
' DoCmd.Hourglass False
' Exit Sub
'
'Err_btnMailMerge_Click:
' ' Display errormessage, delete Word Object and go to common
exit routine
' MsgBox "Error # " & Err.Number & ": " & Err.Description
' Set gobjWord = Nothing
' Resume Exit_btnMailMerge_Click
End Sub
I copied this code out of a book "Alison Balter's Mastering Access 2002 Desktop Development," and it appears that this code is supposed to be able to perform the mail merge and place all of the letters in print preview mode. However, after the error, I have to manually create the mail merge. Although the merge letter does open, I have to open the data source and of course, the Access program stops running.
Any suggestions?
Thanks in advance,
David
Access using an Access Query as my data source. The VBA code takes me
to Word from Access and opens my merge letter, but I get the following
error after Word has loaded:
Error #5852
Requested Object not available
The following is the VBA code that the VBA debugger gives me after the
error.
.Destination = wdSendTonewDocument
And this is the code that I use:
Private Sub btnMailMerge_Click()
' On Error GoTo Err_btnMailMerge_Click
Dim strMergeLetterName as String
' Turn Hourglass on
DoCmd.Hourglass True
' Attempt to create a Word object
If CreateWordObj() Then
' If Word object created
With gobjWord
' Make Word Visible
.Visible = True
strMergeLetterName = "\"
strMergeLetterName = strMergeLetterName & txtMergeLetterName
' Open document
.Documents.Open CurrentProject.Path & txtMergeLetterName
' Give the document time to open
DoEvents
'Use the mailmerge method of the document to perform a
mail merge
With gobjWord.ActiveDocument.Ma
.Destination = wdSendTonewDocument
.SuppressBlankLines = True
.Execute
End With
' Send results of the Mailmerge to the print preview window
.ActiveDocument.PrintPrevi
' Make Word visible
.Visible = True
End With
End If
'Exit_btnMailMerge_Click:
' ' Turn hourglass off
' DoCmd.Hourglass False
' Exit Sub
'
'Err_btnMailMerge_Click:
' ' Display errormessage, delete Word Object and go to common
exit routine
' MsgBox "Error # " & Err.Number & ": " & Err.Description
' Set gobjWord = Nothing
' Resume Exit_btnMailMerge_Click
End Sub
I copied this code out of a book "Alison Balter's Mastering Access 2002 Desktop Development," and it appears that this code is supposed to be able to perform the mail merge and place all of the letters in print preview mode. However, after the error, I have to manually create the mail merge. Although the merge letter does open, I have to open the data source and of course, the Access program stops running.
Any suggestions?
Thanks in advance,
David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.