Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

How to print MS Access OLE Word Document using automation

I have an Access table that includes an OLE field containing an MS word document.   Presently I export information from this table and import it into a Word document for reporting purposes (using automation).  However  I am not including the OLE Word field but now wish to do so.  I need a copy of this embedded word file to include in my existing word report  but cannot see how to do this.
 
0
BethWoodhouse
Asked:
BethWoodhouse
  • 3
  • 3
1 Solution
 
Jeffrey CoachmanCommented:
BethWoodhouse,

Can I ask why you don't do your reporting in Access?
Thus avoiding all this OLE "Round-Tripping"

JeffCoachman
0
 
BethWoodhouseAuthor Commented:
Because it is an existing system that reports in word by exporting and doing a merge and I want to add more data to it.  However I would still like to know how to print the OLE contents in Access!
0
 
Jeffrey CoachmanCommented:
OK
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BethWoodhouseAuthor Commented:
I cannot see anything! Did you forget a link or an attachment?
0
 
Jeffrey CoachmanCommented:
No, I was just saying OK.
0
 
BethWoodhouseAuthor Commented:
Thanks but I have found what I need on the microsoft site.  I will now close the question, thanks all the same.
 

Sub CopyDocument_Click ()
          Dim NewObject As Object
          Dim NewDoc As String
          Dim DocPath As String

          ' Name of the new document to create.
          NewDoc = "TEST.DOC"

          ' Where to store the new document.
          ' DefaultDir$(9) returns the Word directory path.
          ' See DefaultDir$() in Word's on-line help for more options.
          ' Note: The "$" is not used when calling DefaultDir via
          ' OLE Automation.
          DocPath = Me!MyOle.Object.Application.WordBasic.DefaultDir(9)

          ' Copies the embedded object to Clipboard.
          Me!MyOle.Verb = 0
          Me!MyOle.Action = 7
          Me!MyOle.Object.Application.WordBasic.EditSelectAll
          Me!MyOle.Object.Application.WordBasic.EditCopy
          Me!MyOle.Action = 9
          DoEvents

          ' Creates a new document and pastes Clipboard contents.
          ' Saves the document in the Word directory and closes the
          ' document.
          Set NewObject = CreateObject("Word.Basic")
          NewObject.FileNew
          NewObject.EditPaste
          NewObject.FileSaveAs DocPath & "\" & NewDoc
          NewObject.FileClose

          ' Frees the memory used by the objects.
          Set NewObject = Nothing
          MsgBox DocPath & "\" & NewDoc & " was created successfully."
      End Sub
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now