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!

Emailing Selected Reports

Status
Not open for further replies.

mommom

Technical User
Nov 14, 2003
208
US
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?
 
Hi Mommom!

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).

Hope this all helps.
Best wishes.

Magnetar [atom]
 
I have three reports that someone can select from. So under the object name I don't want to put only one report.
 
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. ", , False

Exit_Command173_Click:
Exit Sub

Err_Command173_Click:
MsgBox Err.Description
Resume Exit_Command173_Click


End Sub
********
Just trying to give a little Back, UncleG
 
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.
 
Hello,

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

'//////////////////////////////////////////////////////////////////////////////////////////


Set Fso = New FileSystemObject


'Subject Line

Subjectline = "My Reports"


BodyFile$ = "My Reports for Wednesday."
myBodyText = "Text to Include"


' Open Outlook
Set MyOutlook = New Outlook.Application


' Creates the e-mail

Set Email = MyOutlook.CreateItem(olMailItem)


' Addressee

Email.To = "Addressee@com.com"

'Subject Line

Email.Subject = Subjectline$

'Message Body

Email.Body = myBodyText

'Attachements

If AlphaReport = 1 Then

Email.Attachments.Add Attachment1

End If


If ExecutiveReport = 1 Then

Email.Attachments.Add Attachment2


End If

If CellNumber = 1 Then

Email.Attachments.Add Attachment3

End If

MsgBox "Sending out Weekly Reports." & vbCrLf & vbLf & _
"Please Select OK when Prompted by Outlook." & vbCrLf & vbLf & _
"Thank You", vbExclamation, "Sending Email"

Email.Send


Set Email = Nothing

Set MyOutlook = Nothing


Exit Sub


Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

Hope that helps

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top