Sending Reports Automatically to MS Word

A

Anthony

Hi All

I know that it is possible to send reports to Word automatically using the
OutputTo command within a macro.

But...does anyone know if I can give the Word doc an unique name using this
method, preferably by incorporating one or more fields from a table into the
doc name? Is there another way to achieve this objective?

Thanks in advance for any suggestions.

Anthony
 
S

Steve Schapel

Anthony,

You can use an expression in the Output File argument of the OutputTo
macro action. For example...
="C:\MyReports\Stats" & [Forms]![MyForm]![MyField] & ".rtf"
 
A

Anthony

Hi Steve

Thanks for you response. I created a macro, which included the line of code
you suggested. This macro runs when the Report opens (ie OnOpen). However, I
kept getting an error message (ie "MS Access can't find the form "My Form"
referred to in a macro expression of VB code"). I tried fixing this by
adding a line of code elsewhere so that "My Form" remains open while the
macro runs. This time I received an error message telling me that, "This
action can't be carried out while processing a form or report event".

Any further suggestions???

Steve Schapel said:
Anthony,

You can use an expression in the Output File argument of the OutputTo
macro action. For example...
="C:\MyReports\Stats" & [Forms]![MyForm]![MyField] & ".rtf"

--
Steve Schapel, Microsoft Access MVP

Hi All

I know that it is possible to send reports to Word automatically using the
OutputTo command within a macro.

But...does anyone know if I can give the Word doc an unique name using this
method, preferably by incorporating one or more fields from a table into the
doc name? Is there another way to achieve this objective?

Thanks in advance for any suggestions.

Anthony
 
S

Steve Schapel

Anthony,

What is your purpose in opening the report? I had assumed you were
triggering the OutputTo from an event on a form. As you discovered, my
suggestion relies, also, on an assumption that the data you want
included in the exported document name is represented in a control or
controls on a form which is open at the time.

If you still can't get it working, maybe it would help if you post back
with some more details, perhaps with examples, of what you want.
 
A

Anthony

Hi Steve

My database is set up so that the user enters data in one form (patient
details), then presses a command button, which closes that form and opens
another (ie operation details) into which more data are entered. A command
button on the Operation Details form then closes this form and opens a
report displaying data for a patient's operation. At the moment, I must
press the MS Word icon on the toolbar to export the report to word. I want
this process to occur automatically, so that the report is saved as a word
doc with an unique name.

Can your original suggestion be applied to this case, or is there another
approach that will produce the desired results?

Thanks again
Anthony
 
S

Steve Schapel

Anthony,

Yes, assign your macro on the button on the form, not the Open event of
the report.
 
S

Steve Schapel

Anthony,

By the way, the information that Albert referred to in his reply is cool!
 
A

Anthony

Hi Albert

Your word merge example is very nifty. I tried incorporating it (and the
code) into my database but encountered the following problems:

1. I get an error (ie "Compile Error: Sub or function not defined") when I
click on the
MergeSingleWord command button.

2. I get the same error message when I try to open the GuiWordTemplate
directly.

On your web site, you mention that the Microsoft DAO 3.6 Object Library in
the references window must be set. Could this be the cause of these problems
and, if so, how do I set this object library.

Thanks in advance
Anthony
 
A

Anthony

Hi again

I managed to figure out how to set the Microsoft DAO 3.6 Object Library, but
this did not help solve the problems with undefined subs/functions. Any
suggestions?

Anthony
 
A

Anthony

Yeay!!!!

Albert, I figured out how to get your code/forms working (almost
perfectly!). After a couple of hours trying to figure out what the problem
was, I finally realised that I had forgotten to include the modules.

The only problem I have now is that the merge produces a document containing
letters for all records. Any clues as to how I can fix this?

When moving between forms, I have been using the following line
stLinkCriteria in the "Open Form" command to get to the record for a
particular patient:

stLinkCriteria = "[PatientID]=" & Me![PatientID]

I tried incorporating this into your module that opens the "GuiWordTemplate"
form, but it seemed to choke on "Me". Any suggestions?

Many thanks
Anthony
 
Top