Output Each Page Bread to new Document

B

Bev

I have a report that creates a single document that produces several faxes
for different clients. I need a way to send each page to a separate document
in the print process.

Is this possible.
 
D

Dale Fye

Bev,

The challenge her is that although the OpenReport method accepts a WHERE
clause as a parameter to restrict the output. The downside is that this
parameter is not available when you use the OutputTo or SendObjects methods.
So, what I do is create a function which returns a value (in this case we'll
call it fnClientID). This function would be placed in a code module, and
would look like:

Public Function fnClientID(Optional SomeValue as Variant = NULL) as long

'using a static variable ensures that you can use this funtion from
'anywhere in your application and it will retain it value. This is
'similar to a global variable, but can be used in saved queries, which
'global variables cannot.
Static myClientID as long

If NOT ISNULL(SomeValue) then myClientID = SomeValue
fnClientID = myClientID

End Function

To use this function, you can send it a value: Call fnClientID(3)
or retrieve a value: debug.print fnClientID

I then add field to my query for the report, something like:
IncludeClient: fnClientID()
Criteria: 0 or [ClientID]

So your query might actually look like:

SELECT * FROM tblClients
WHERE fnClientID() = 0 or fnClientID = [ClientID]

Generally, I will have command button on my form to do this kind of export.
In that buttons click event, I will have some code that does something like:

Private sub cmd_Export_Click

Dim rs as DAO.Recordset
Dim strSQL as string

strSQL = "SELECT ClientID from tblClients"
set rs = currentdb.openrecordset(strsql)

While not rs.eof
Call fnClient(rs("ClientID"))

docmd.OutputTo acOutputReport, "reportname", acFormatSNP, _
"C:\Temp\" & format(date(), "yyyy-mm-dd") & "_Client_" _
& fnClientID() & ".snp"

rs.movenext
wend
rs.close
set rs = nothing

end sub

What this does, is loops through the list of clients (assumes you want to do
all of your clients each day) and stores the clientID in fnClientID function.
Since the reports query is looking at that function, it only generates the
report for the single client and exports it (OutputTo method) to a file on
the C:\Temp\ folder with the days date and the clients ID. If you actually
need to send this to your clients, you might want to use the SendObject
method instead of the OutputTo method.

If you want to run the report that contains all of the various clients, then
just send a zero to the function, like: Call fnClientID(0)

HTH
Dale
 
D

Dale Fye

Actually, now that I read your post more closely, it says you want to fax
this stuff, so you could replace the OutputTo method with the OpenReport
method, and it would print each clients document consecutively.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top