I would like to create a button on a form that I can click and pick a report and have it automatically attach as an Outlook attachment. Is there a way to do that?
One (very) quick, easy way to do this (i.e. the 'non-VBA' route), would be to run a macro from your button, which places a report at an attachment within Outlook.
Within your macro, - call it mcrSendRpt, say:
1. Select action SendObject
2. At bottom right-hand corner of macro properties, select:
Object Type = Report
Object Name = {Name of your report}
Output Format = {Report output format of your choice}
Set ‘Edit Message’ to either ‘Yes’ or ‘No’, depending on whether you want to edit the email message before sending it.
On your button properties, under ‘Event’ select the ‘mcrSendRpt say, in order to execute the above procedure.
(Check out the ‘SendObject Action’ within the help menu for further details).
Hi mommom,
From a command button, I use the code below to send email in SNP Format. My forms and reports are driven by queries and give the user the option to print 1 or 2 copies and or Email the report.(via 3 seperate buttons)
If you can print it you can email it. The (someone@ verizon.net entry sends a blind copy to a backup account on our server, leave this blank if you prefer not to do so.
Experiment with changing acFormatSNP to acFormatHTML or acFormatRTF to achieve the desired appearance or compatability.
The below code opens the report in preview then passes it to outlook or outlook express as an attachment, Fills in the Subject Line then Stopping to allow you to add a further note in the body of the email or send to additional persons. Of course you will need to substitute your stDocName = [YourReportName] and varCriteria = [YourRecID] and target email address "Me!Email"(where it is to go) in order for this to work for you.
******
Private Sub Command173_Click()
On Error GoTo Err_Command173_Click
Me.Refresh
Dim stDocName As String
Dim VarCriteria As String
stDocName = "rptPurchaseOrder"
VarCriteria = "[WoPoID]=" & Me![WoPoID] & ""
DoCmd.OpenReport stDocName, acPreview, , VarCriteria
DoCmd.SendObject acSendReport, "rptPurchaseOrder", acFormatSNP, Me!Email, , "someone@verizon.net", "PO Number " & Me!WoPoID & " P/N " & Me!Partno, "Your PO is attached in SNP Format If unable to open download and install the free Access Snapshot Viewer at.
My dillema is that the users can choose between 3 different reports Alpha Report, Executive Report, and Cell number report. How can I create on a command button that when you click it will ask you which report you would like to email and attach that report to Outlook.
One way you can achieve this is create three unbound checkboxes on a form. Call them ckAlpha,ckExecutive,ckCellNumber. The Email will attach the reports if they are checked.
Add the following references to your db: MsOutlook Object, Ms Scripting Runtime and DAO 3.6
Create a button and call it cmdEmail.
Paste this in to the 'On Click' Event of the button and modify accordingly:
Dim MyOutlook As Outlook.Application
Dim Email As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim Fso As FileSystemObject
Dim MyBody As TextStream
Dim myBodyText As String
Dim Addressee As String
Dim AlphaReport, ExecutiveReport, CellNumber As Integer
Dim Attachment1 As String 'Alpha Report
Dim Attachment2 As String 'Executive Report
Dim Attachment3 As String 'Cell Number
'See what Files have been checked and output to Snapshot
If Me.ckAlpha = -1 Then
DoCmd.OutputTo acOutputReport, "AlphaReport", acFormatSNP, "C:\Snapshots\AlphaReport.snp"
Attachment1 = "C:\Snapshots\AlphaReport.snp"
AlphaReport = 1
End If
If Me.ckExecutive = -1 Then
DoCmd.OutputTo acOutputReport, "ExecutiveReport", acFormatSNP, "C:\Snapshots\ExecutiveReport.snp"
Attachment2 = "C:\Snapshots\ExecutiveReport.snp"
ExecutiveReport = 1
End If
If Me.ckCellNumber = -1 Then
DoCmd.OutputTo acOutputReport, "CellNumber", acFormatSNP, "C:\Snapshots\CellNumber.snp"
Attachment3 = "C:\Snapshots\CellNumber.snp"
CellNumber = 1
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.