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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Report to email (outlook)

Status
Not open for further replies.

ajolson1964

Programmer
Mar 25, 2008
31
US
Is there a way to have a command button output a Report to outlook email as a snapshot or excel file?
 
Hows it - this is what I use to send a snapshot report. Run from a command button

HTH's

Code:
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

Take it Easy
Man with one chopstick go hungry
 
Thanks a little tinkering and it works great for my applications. Gonna see if I can call it up as a function but if not coded in a command button will be fine. Again Thanks exaclty what I needed!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top