Set caption of closed report for email attachment (1 Viewer)

Keith Nichols

Registered User.
Local time
Today, 21:40
Joined
Jan 27, 2006
Messages
431
Hi there,

I posted a question about this a while ago and got no response. The only thing I found on a search was a dead link to a solution, so I hope you will forgive me for posting again.

I email reports from a button on my form. All works fine but the attachment to the email has the caption name as the file name.snp (or whatever format you choose such as .rtf). Users will potentially be distributing numerous reprots by email and those that want to file them would benefit from having a meaningful name such as something reflecting hte contents and the report date.

I can reset the caption to reflect the report contents in the on open event, but the attachment filename has already been generated at this point. From other posts, it seems that a closed report is treated as a document and the caption can be set before it is opened, but I have no idea whatsoever on how to do this.

Any hints anybody?

Oh, and happy holidays all round. :)
 

Moniker

VBA Pro
Local time
Today, 13:40
Joined
Dec 21, 2006
Messages
1,567
After you populate the report (as in, set it's control source properly, either in report code or some other method), it doesn't matter if it's open or closed. Use an OutputTo method, like this:

DoCmd.OutputTo acOutputReport, "Name_Of_Report_In_Your_DB", acFormatSNP, [custom_output_path/filename],False

With that command, the format is:

DoCmd.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

Only ObjectType (in our case, acOutputReport) is required. The rest are optional. (I used acFormatSNP as the output format to match your example. See the Access built-in help on OutputTo for all the formats.)

Also note that I added a "False" for AutoStart. If it's true, then the snapshot viewer would automatically open to that file after it was saved, which is sort of a pain.

I think if you play with DoCmd.OutputTo as described, you'll get your filename stuff worked out.

~Moniker
 
Last edited:

Keith Nichols

Registered User.
Local time
Today, 21:40
Joined
Jan 27, 2006
Messages
431
Moniker said:
After you populate the report (as in, set it's control source properly, either in report code or some other method), it doesn't matter if it's open or closed. Use an OutputTo method, like this:

DoCmd.OutputTo acOutputReport, "Name_Of_Report_In_Your_DB", acFormatSNP, [custom_output_path/filename],False

With that command, the format is:

DoCmd.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

Only ObjectType (in our case, acOutputReport) is required. The rest are optional. (I used acFormatSNP as the output format to match your example. See the Access built-in help on OutputTo for all the formats.)

Also note that I added a "False" for AutoStart. If it's true, then the snapshot viewer would automatically open to that file after it was saved, which is sort of a pain.

I think if you play with DoCmd.OutputTo as described, you'll get your filename stuff worked out.

~Moniker

Hi Miniker,

Thanks for the reply, although I'm not sure I understand it in relation to my problem.

My report button outputs to preview, print or email depending on an if/then that looks at a frame select. Because of this, I want the report to be the same for the three options. The caption is not important for the preview or print options but sets the filename for the email report.

As it stands, the caption can be set once the report is open. What I am trying to do is to set the caption before it is open so the outputTo will pick it up as the filename

Is your solution suitable for this situation and where would I put the code?
 

Moniker

VBA Pro
Local time
Today, 13:40
Joined
Dec 21, 2006
Messages
1,567
You can't set the caption of a form or report without that form or report being open (as far as I know). If I'm wrong on that, someone please correct (and enlighten) me. :)

The way to code around it is if they select the email option (which you're already capturing), then open the report, change the caption, close the report, and then continue with your emailing code. That can all be done in code.

~Moniker
 

Keith Nichols

Registered User.
Local time
Today, 21:40
Joined
Jan 27, 2006
Messages
431
Thanks Moniker,

That makes sense and I think I should be able to get it worked out - open, set caption, close, reopen & mail :) .

I did read another post that claimed a closed report could have the caption reset but the link to the sample db was broken. :rolleyes:
 

Users who are viewing this thread

Top Bottom