Automate Emailing of an access report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chilipalmer
    New Member
    • Apr 2010
    • 1

    #1

    Automate Emailing of an access report

    I have an access 2002 database. I have code that emails an report to people that are in a table. However to send the emails I have to hit the send button on outlook express for each email. Is there are way to NOT have to do this? Below is my code.

    Option Compare Database
    Option Explicit

    Private Sub Command0_Click( )
    Dim strSQL As String
    Dim rs As DAO.Recordset
    Dim intLoop As Integer
    Dim rpt As Report

    On Error GoTo ProcError

    strSQL = "SELECT DISTINCT Therapist_Name, email_address FROM tbl_credentials Due_fromqry"
    Set rs = CurrentDb.OpenR ecordset(strSQL , , dbfailonerror)
    If rs.EOF Then GoTo ProcExit

    DoCmd.OpenRepor t "Policy_letter" , acViewPreview
    Set rpt = Reports("Policy _letter")

    rs.MoveFirst
    While Not rs.EOF
    rpt.Filter = "[Therapist_Name] = '" & rs("Therapist_N ame") & "'"
    rpt.FilterOn = True
    Pause 1
    rpt.Caption = "Policy"
    DoCmd.SendObjec t acSendReport, rpt.Name, acFormatRTF, rs("Email_addre ss"), , , _
    "Policy ", "Attached is the Policy, please read."
    rs.MoveNext
    Wend

    ProcExit:
    rs.Close
    Set rs = Nothing
    DoCmd.Close acReport, rpt.Name
    Exit Sub

    ProcError:
    MsgBox Err.Number & vbCrLf & Err.Description , vbOKOnly, "Error sending reports"
    Debug.Print Err.Number, Err.Description
    Resume ProcExit
    End Sub

    Public Sub Pause(duration As Double)

    'accepts a parameter which is the number of seconds and partial seconds to pause execution of other code.
    Dim dblTimer As Double

    dblTimer = Timer
    While dblTimer + duration > Timer
    DoEvents
    Wend
    End Sub
Working...