• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 46
  • Last Modified:

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"

    '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"
        End With
    'End of email routine

    End If

Open in new window

1 Solution
Fabrice LambertFabrice LambertCommented:
The display method is not a blocking instruction, so the window close as soon as you send it.

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


End If

Open in new window

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Remove this line:


The .Display line should show the user the email, and allow them to send it manually.
SteveL13Author Commented:
Thank you. Pretty obvious and I missed it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now