Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Error on Word Merge - MS Office 2010

Status
Not open for further replies.

LarryDeLaruelle

Technical User
Joined
May 19, 2000
Messages
1,055
Location
US
In earlier versions of access, this code worked fine to merge and save a document.

Private Sub cmdMerge_Click()
Dim strFileName As String
Dim strFilePath As String
Dim strMergeFile As String
Dim objWord As New Word.Application
Dim objDoc As Word.Document

objWord.Application.Visible = False

Set objDoc = objWord.Documents.Open("G:\Database\TCC_KidCare\WordDocs\" & strMergeFile)

‘This is the line that errors – Run Time Error 5832; Requested object is not available
objDoc.MailMerge.Destination = wdSendToNewDocument

objDoc.MailMerge.Execute

objWord.Application.Documents(1).SaveAs (strFilePath & strFileName)

objWord.Application.Documents(2).Close wdDoNotSaveChanges

objWord.Application.Documents(strFileName & ".doc").Close

objWord.Application.Quit

Set objWord = Nothing

Set objDoc = Nothing



End Sub

It now errors on the line objDoc.MailMerge.Destination = wdSendToNewDocument.

We are using Office 2010, 32 Bit. I have set the VBA references (in Access) to the 14.0 version of Word and Office.

I have manually processed the merge in Word without a problem.

Any assistance will be greatly appreciated.


Larry De Laruelle

 
Where is set the value of strMergeFile ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply.

strMergeFile is the name of the word document (template) used in the merge; it is set up to use a temporary table created earlier in the process.

strFilename is the name the merged document is to be save as; strFilePath defines the location where the document is to be saved.

Larry De Laruelle

 
So, seems like you didn't post the whole code ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
LarryDeLaruelle . . .

In reference to ...
Code:
[blue]   Dim strFileName As String
   Dim strFilePath As String
   Dim [purple][b]strMergeFile[/b][/purple] As String
   Dim objWord As New Word.Application
   Dim objDoc As Word.Document

   objWord.Application.Visible = False

   Set objDoc = objWord.Documents.Open("G:\Database\TCC_KidCare\WordDocs\" & [purple][b]strMergeFile[/b][/purple])[/blue]
... [purple]strMergeFile[/purple] is [red]not defined![/red] (already pointed out by [blue]PHV[/blue]).

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The parts of the code missing are the value assignments for those variables.

strMergeFile is set by the user from a combo box after update event; strFileName is set in that same event. strFilePath is set by the user to point to the folder where the new document is to be saved.

I didn't include that portion of the code since it seemed immaterial to the error I'm receiving.

Larry De Laruelle

 
LarryDeLaruelle . . .
LarryDeLaruelle said:
[blue][purple]It now errors[/purple] on the line objDoc.MailMerge.Destination = wdSendToNewDocument.[/blue]
Any error number? Whats the error message?





See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The error is: "Run Time Error 5832; Requested object is not available"



Larry De Laruelle

 
LarryDeLaruelle . . .

In the VBA [blue]Object Browser[/blue] perform a search for [blue]wdSendToNewDocument[/blue]. Does it show up?

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Yes it does.
Library = Word;
Class = WdMailMergeDestination;
Member = wdSendToNewDocument

Larry De Laruelle

 
LarryDeLaruelle . . .

Hmmm ... I'm left with three ideas:
[ol][li][blue]strMergeFile[/blue] has a space in it, however I'd expect to get an error relating to [blue]file not found[/blue]. To verify just select a name with no spaces.[/li]
[li][blue]objWord[/blue] is not set. This may have something to do early/late binding.[/li]
[li]The successor version of access your using has problems with [blue]MailMerge.Destination[/blue]. This appears to standout the most.[/li][/ol]
Post the full code for [blue]cmdMerge_Click()[/blue]. Also post the access version this occurs under. In the meantime perform a search for problems with [blue]MailMerge[/blue].

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks to all who responded. Here is the solution:

With objDoc.MailMerge
.MainDocumentType = wdFormLetters
.Destination = wdSendToNewDocument
.OpenDataSource _
Name:="G:\ Location\Db.accdb", _
sqlstatement:="SELECT * FROM [tblSource]"
.Execute
End With

It appears that Word 2010 requires more information for merges.


Larry De Laruelle

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top