Web Development

General discussion


AccessXP:OLE Obj Mailmerge

By nlarge ·
Hope someone can help here.

I have a table table1 ID Autonumber,Obj OLE Object, and have created a form for this table.
I have inserted a button on my form. When I click this button I want to open the embedded OLE word document, in word, then use a data source (in code), and run it as a mailmerge, then refer to the mailmerge as an item of type "Word.Document", so I can insert it into a record in an access database.
However, the code (below) opens the document (as a picture!), then mailmerges a picture of the word document a number of times.

Dim wapp As Word.Application
Dim wrge As Word.Range
Dim wDoc As New Word.Document
Set wapp = CreateObject("Word.Application.10") 'the word object
Set wDoc = wapp.Documents.Add 'creates areference to a new doc created in wapp
Set wrge = wDoc.Range 'the "body" of the new word document
Me.Obj.Verb = -2 'Activates the object for editing
Me.Obj.Action = acOLECopy 'Copies the object to the Clipboard. see acOLECopy in Action in MSDN
Debug.Print Me.Obj.LpOleObject 'prints memory address of the ole object, worth a try??
Me.Obj.Action = acOLEActivate 'activates the object for editing
wDoc.Range.Paste 'pastes the object into the word document, probably why its just pasting the picture, rather than the word document itself
wDoc.MailMerge.MainDocumentType = wdFormLetters
wDoc.MailMerge.OpenDataSource (CurrentProject.Path & "\" & CurrentProject.Name), , , , False, , , , , , , , "select * from tmpStdQryOrg", , False 'tmpstdQryOrg is just an example query to use as a datasource
wDoc.MailMerge.Execute (True) 'executes the mailmerge
wDoc.Activate 'activates the word document
wrge.InsertAfter "Hello, my name is fred" ' a test line
Debug.Print "State = " & wDoc.MailMerge.State 'to see if it is a mailmerge doc or not
wDoc.Activate 'activate the word doc
wapp.Visible = True 'make sure you can see the word application

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Related Discussions

Related Forums