Print a (variable) Word doc with an Access report

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)
WMorrisseyAsked:
Who is Participating?
 
Nico BontenbalCommented:
<<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
 
Nico BontenbalCommented:
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
 
aikimarkCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
WMorrisseyAuthor Commented:
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
 
aikimarkCommented:
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
 
WMorrisseyAuthor Commented:
The report is printed one record at a time -- it is basically a letter to clients.
0
 
aikimarkCommented:
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
 
WMorrisseyAuthor Commented:
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
 
aikimarkCommented:
Question: If you specify a document at design time, can your report event code make the object visible/invisible at run time?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.