Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command button to export and email a report as snapshot attachment

Status
Not open for further replies.

marioman

Technical User
May 13, 2002
6
GB
Can anyone help with a bit of code to export a report, based on information in a form, to snapshot format and then email it using outlook - all from a command button. The recipient addresses will always be the same and the body of the email, just the attachment changes monthly when the report is run.

Thank you.
 
Created from command button wizard report options mail report. Hopefully, this will be enough to get you started.

Good Luck!


Private Sub cmdeMailReport_Click()
On Error GoTo Err_cmdeMailReport_Click

Dim stDocName As String

stDocName = "rptCities"
DoCmd.SendObject acReport, stDocName

Exit_cmdeMailReport_Click:
Exit Sub

Err_cmdeMailReport_Click:
MsgBox Err.Description
Resume Exit_cmdeMailReport_Click

End Sub
 
More complete example:

ToAddress is valid recipient email address in double quotes
CCAddress is valid cc email address in double quotes
BCCAddress is valid bcc email address in double quotes

If you don't need some of them just hold the place with a ,

Report will be sent as an attachment

Private Sub cmdeMailReport_Click()
On Error GoTo Err_cmdeMailReport_Click

DoCmd.SendObject "rptCities",,"ToAddress@work.com", _
"CCAddress@someplace.com", "BCCAddress@someplace.com", _
"Subject Line", "Message Body"

Exit_cmdeMailReport_Click:
Exit Sub

Err_cmdeMailReport_Click:
MsgBox Err.Description
Resume Exit_cmdeMailReport_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top