Report Filter

G

Guest

I have the following code set up to output a report to a .snp file but I want
it to filter to the record I have opened on my form. I can filter it to print
the report from another command button but I don't know how to filter it to a
file. Can anyone shed some light on this for me?

DoCmd.OutputTo acOutputReport, "rptCARequest", "SnapshotFormat(*.snp)",
"C:\CARequest.snp", False

How would I add my "qryCAFilter" to this code to filter the report correctly?
 
G

Guest

The code behind your command button to print the report using your filter
will probably look something like this:

DoCmd.OpenReport "ReportName", acViewNormal , "qryCAFilter"
or
DoCmd.OpenReport "ReportName", acViewNormal , , "ID=3"

In order to output the report to a snapshot file using the filter, open the
report in preview:
DoCmd.OpenReport "ReportName", acViewPreview , "qryCAFilter"

and then make sure to select the report:
DoCmd.SelectObject acReport, "ReportName"

then output the report from screen to the snapshot file:
DoCmd.OutputTo acOutputReport, "ReportName", acFormatSNP,
"c:\folder\filename.snp", False

make sure to close the report:
DoCmd.Close acReport, "ReportName", acSaveNo

Hope this helps.
 
G

Guest

Hi Andrew,
Yes that helps a lot but what if I wanted to do this without previewing my
report? Can it be done just from a command button on the form?
 
G

Guest

The simple answer is no. You could make the report invisible immediately
after you preview it:

Reports("ReportName").Visible = False

If that produced too much flicker for you you could turn off screen updating
while the report was sent to the snapshot file:

place this just before the DoCmd.OpenReport...
Application.Echo False

But make sure to turn screen updating on.
Application.Echo True
placed just after the DoCmd.Close acReport...
 
G

Guest

I'll go with just making the report invisible immediately. There isn't too
much flicker so it shouldn't be a big deal. I appreciate your help with this.
Thanks!
 
G

Guest

Actually I have one followup question. Right now my code is sending this to a
file on the "C:\" drive. How do I overwrite this file every time this code
runs? Basically what I'm trying to do is create a temp .snp file and then
emailing it to certain people. I have my email code firing after the file is
created but it's not overwriting the file everytime I run this code.
 
G

Guest

Or can I skip the file creation part and just email it as a snapshot format?

Here is the code I'm using in my email portion:

..Attachment.Add "C:\CARequest.snp"

Can I just have that point to the report instead of using a file?
 
G

Guest

In order to eMail it you would have to first create the temporary snapshot
file. Before you create the file check to see if it already exists, if so
delete it and then carry on processing.

Before outputting the previewed report to the snapshot file check to see if
it exists:
If Dir("c:\folder\filename.snp") <> "" Then
Kill "c:\folder\filename.snp"
EndIf

Hope this helps.
 

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

Similar Threads


Top