Solved

How to print MS Access OLE Word Document using automation

Posted on 2008-10-24
6
527 Views
Last Modified: 2013-12-25
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
Comment
Question by:BethWoodhouse
  • 3
  • 3
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22801014
BethWoodhouse,

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

JeffCoachman
0
 

Author Comment

by:BethWoodhouse
ID: 22801783
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22803910
OK
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:BethWoodhouse
ID: 22804941
I cannot see anything! Did you forget a link or an attachment?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22806202
No, I was just saying OK.
0
 

Accepted Solution

by:
BethWoodhouse earned 0 total points
ID: 22806561
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now