send e-mail automacticallv (1 Viewer)

rainbows

Registered User.
Local time
Yesterday, 19:17
Joined
Apr 21, 2017
Messages
425
hi,

this is some code tht I found and modified to suit me own reports etc

how can I change it so it send the e-mail without asking me to press the send button in outlook

Code:
im strCriteria As String
    Dim thisCriteria As String
    Dim eMail As String
    Dim Title As String
    Dim Message As String
    Dim i As Integer
    DoCmd.OpenForm FormName:="ReportDialog", WindowMode:=acDialog
    '* check if [TextReportOption] <> 0
    If Me.TextReportOption <> 0 Then
        strCriteria = "(1=1)" '(1=1) means it is always True, therefore returns all records
        Select Case Me.TextReportOption
        Case Is = 1 'Print Preview
            '* Open the report with criteria
            DoCmd.OpenReport REPORTNAME:=cboReports, VIEW:=acViewReport, WHERECONDITION:=strCriteria
        Case Is = 2 'Print
            '* Open the report with criteria
            DoCmd.OpenReport REPORTNAME:=cboReports, VIEW:=acViewNormal, WHERECONDITION:=strCriteria
        Case Is = 3 'Email report
        
            If cboReports = "Open Issues" Then
                strCriteria = "[STATUS]=""ACTIVE"""
                If DCount("1", "Issues", "Status=""Active""") <> 0 Then
                    With CurrentDb.OpenRecordset("SELECT DISTINCT [Assigned To] FROM [Issues] " & _
                                        "WHERE [Status]=""Active""")
                        If Not (.BOF And .EOF) Then .MoveFirst
                        i = 0
                        While Not .EOF
                            i = i + 1
                            thisCriteria = strCriteria & " And [Assigned To]=" & Nz(.Fields(0).Value, 0)
                            eMail = DLookup("[E-mail Address]", "Contacts", "ID=" & Nz(.Fields(0).Value, 0))
                            '* close report if already open
                            If SysCmd(acSysCmdGetObjectState, acReport, cboReports.Value) <> 0 Then
                                DoCmd.Close acReport, cboReports.Value
                            End If
                            DoCmd.OpenReport REPORTNAME:=cboReports, VIEW:=acViewPreview, WHERECONDITION:=thisCriteria
                            '* this is a test
                            '* DoCmd.OutputTo acOutputReport, cboReports.Value, acFormatPDF, Environ("userprofile") & "\documents\rpt" & i & ".pdf", True
                            DoCmd.SendObject acSendReport, cboReports.Value, acFormatPDF, eMail, , , "Open Issues", _
                                "Your prompt action is required for the following issues!"
                            DoCmd.Close acReport, cboReports.Value

                            .MoveNext


thanks steve
 

isladogs

MVP / VIP
Local time
Today, 03:17
Joined
Jan 14, 2017
Messages
18,218
You could change to a different method of sending email from Access such as using CDO.
Much simpler and Outlook isn't needed at all.
 

shadow9449

Registered User.
Local time
Yesterday, 22:17
Joined
Mar 5, 2004
Messages
1,037
You could change to a different method of sending email from Access such as using CDO.
Much simpler and Outlook isn't needed at all.

That's Daniel's third and preferred solution on the page I referenced.
 

isladogs

MVP / VIP
Local time
Today, 03:17
Joined
Jan 14, 2017
Messages
18,218
Is that so? Glad to hear that Daniel agrees with me. :D
 

Users who are viewing this thread

Top Bottom