ajolson1964
Programmer
Is there a way to have a command button output a Report to outlook email as a snapshot or excel file?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click
'Stop
Dim stWhere As String '-- Criteria for DLookup
Dim varTo As Variant '-- Address for SendObject
Dim stText As String '-- E-mail text
Dim stSubject As String '-- Subject line of e-mail
Dim stTicketID As String '-- The ticket ID from form
Dim stWho As String '-- Reference to tblCustomers
Dim errLoop As Error
Dim stDocName As String '-- Specify the report to send
Dim strName As String '-- Specify Addressee of email
Dim strTitle As String '-- Specify title of email
Dim varFName As Variant '-- Name for email
Dim varLName As Variant '-- Last Name for email
Dim varTitle As Variant '-- Title for email
'Stop
'-- Combo of names to assign ticket to
stWho = Me.cboEmail
stWhere = "tblUser.userid = " & stWho & ""
'-- Looks up email address from tblUsers
'varTo = DLookup("[Email]", "tblUser", stWhere)
'-- Looks up Title for email from tblusers
'varTitle = DLookup("[Title]", "tblCustomers", stWhere)
'-- Looks up Name for email from tblUsers
varLName = DLookup("[LastName]", "tblUser", stWhere)
'-- Looks up Name for email from tblUsers
varFName = DLookup("[FirstName]", "tblUser", stWhere)
If Me.txtCoy = "Ceridian" Then
varTo = "'"
varTo = varTo & varLName & ", "
varTo = varTo & varFName & "'"
Else
varTo = DLookup("[Email]", "tblUser", stWhere)
End If
stSubject = "Issue log as at "
stSubject = stSubject & Date
stDocName = "rptIssueLog"
stText = "Hi " & varFName & Chr$(13) & Chr$(13) & _
"Please find attached the latest issue log. " & Chr$(13) & Chr$(13) & _
"Best regards " & Chr$(13) & Chr$(13) & _
"Les Lockett" & Chr$(13) & _
"Systems Aanalyst" & Chr$(13) & _
"" & Chr$(13) & Chr$(13) & _
"" & Chr$(13) & Chr$(13) & _
"If you can not open this attachment please download the free snapshot viewer from " & Chr$(13) & _
"microsoft. [URL unfurl="true"]http://www.microsoft.com/downloads/details.aspx?FamilyID=b73df33f-6d74-423d-8274-8b7e6313edfb&DisplayLang=en"[/URL]
'Write the e-mail content for sending to assignee
'DoCmd.SendObject acSendReport, stDocName, acFormatRTF, varTo, , , stSubject, stText, -1
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, varTo, , , stSubject, stText, -1
'Set the update statement to disable command button
On Error GoTo Err_Execute
On Error GoTo 0
Exit Sub
Err_Execute:
' Notify user of any errors that result from
' executing the query.
If DBEngine.Errors.Count > 0 Then
For Each errLoop In DBEngine.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop
End If
Resume Next
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub