?
Solved

Print a (variable) Word doc with an Access report

Posted on 2011-04-26
9
Medium Priority
?
313 Views
Last Modified: 2012-05-11
Is it possible to include a Word document to the end of an Access report, perhaps using an unbound object frame?  Three complications:  1) Sometimes the report should have the document included, and sometimes not, based on a field in the printed record.  2) The document to be included varies based on a path stored in the printed record.  3) The size must grow or shrink based on the document (and take no space if there is no document)
0
Comment
Question by:WMorrissey
  • 4
  • 3
  • 2
9 Comments
 
LVL 22

Expert Comment

by:Nico Bontenbal
ID: 35473151
You can add an Unbound Object Frame to your report and link it to for example the file c:\data\link.docx. Just before opening the report you copy the file you want to display on the report to c:\data\link.docx using the FileCopy statement.
Before you open the report you first open it in design. If there is no document you make the height of the Unbound Object Frame and the section it is in zero. You also perform a .SizeToFit on the Unbound Object Frame.
Then you open the report in PrintPreview and it should give you the results you are looking for.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35474559
you can add code into your Report_Print() or Report_Format() events that will set the properties of the embedded object, based on the value of the current record or some other variable's value.
0
 

Author Comment

by:WMorrissey
ID: 35476113
I was able to add the unbound object frame to a test report, but have been unsuccessful trying to change its properties from the report module.  Also, the object is not reflecting changes to the linked document, even though the OLE type is set at "linked."

Here is my attempt to change the linked document in code:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    OLEUnbound6.SourceDoc = "\\Rcsmn001\rcbid\Instructions\test.doc"
End Sub

(The original document is "\\Rcsmn001\rcbid\Instructions\test2.doc")  And yes, I have double-checked the two documents.  Any ideas?
0
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!

 
LVL 46

Expert Comment

by:aikimark
ID: 35476166
In your question, you stated that the Word content was at the end of your report.  The event code you posted is Detail-related.
0
 

Author Comment

by:WMorrissey
ID: 35476570
The report is printed one record at a time -- it is basically a letter to clients.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35476660
The simplest way to tackle the problem is to have two reports.  One report includes the Word object and the second does not.  Feed the two reports with different queries that select the records that are eligible/not eligible for the extra content.
0
 

Author Comment

by:WMorrissey
ID: 35476714
I'd prefer not to do that, as that means two reports to keep updated, rather than one.

Regardless, I need to figure out why the unbound object control is not reflecting changes to the Word doc.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35476779
Question: If you specify a document at design time, can your report event code make the object visible/invisible at run time?
0
 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 2000 total points
ID: 35478080
<<I need to figure out why the unbound object control is not reflecting changes to the Word doc.>>
You need to use the Action method on the ole object after you set the SourceDoc. See the example in the SourceDoc help. But I didn't get this working in a report. Seems like the object is read only in run time.
So this is why I suggested to link to a document and replace that document with the right document just before opening the report.

I've attached a sample database that can show variable Word documents in a report. It can also hide the document completely. Only thing that doesn't work is the resizing. But I was able to do this manually by using SizeToFit in the design mode. So this should be possible from code also (open report in design, call SizeToFit on Ole object, close and save the report, then run it).
For this sample to work a Word document with the name c:\data\link.docx must exist (or at least the folder c:\data). In the form doc the path and filename of a Word document can be entered (docx). Then the record should be saved and the Report button can be used to open the report.


Word.zip
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

840 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