Avatar of SteveL13
SteveL13
Flag for United States of America asked on

Why is email being sent even though I have .Display turned on

I have the following code in place for an onclick event of a command button.  The mail event is working fine EXCEPT it is not allowing me to preview the email before it gets sent.  Can someone figure out why?

    Dim oOutlook As Object
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim strPath As String
    Dim strFilter As String
    Dim strFile As String
    Dim strAttachmentFolderDataPath As String

    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0

    If oOutlook Is Nothing Then
        MsgBox "Outlook is not open, open Outlook and try again"
    Else

    'Email routine...
    strPath = DLookup("AttachmentDirectory", "LOCALtblDatabaseSetup") & "\" & Me.txtContractN

    strFilter = "*.pdf"
    strFile = Dir(strPath & strFilter)

        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)

        With MailOutLook
            .BodyFormat = olFormatRichText
            .To = "somebody@somewhere.com"
            ''.cc = ""
            ''.bcc = ""
            .Subject = "Report Attached"
            .HTMLBody = "Report Attached"
            .Attachments.Add strPath & "\Report.PDF"
            .Display
            .Send
        End With
    'End of email routine

    End If

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
SteveL13

8/22/2022 - Mon
Fabrice Lambert

Simple:
The display method is not a blocking instruction, so the window close as soon as you send it.
Alan

Hi,

If you add, say, a MsgBox after the .display, before the .send then you can give the user the option.  Something like:

If MsgBox("Okay to Send?),vbYesNo) = vbYes then

    MailOutlook.Send

End If

Open in new window



Alan.
ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SteveL13

ASKER
Thank you. Pretty obvious and I missed it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck