Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Posts
    3

    Unanswered: outlook staying open after sending message

    I am sending an outlook message via MS Access. The problem is the outlook application stays open after I send the message and quit the application.

    I am using the following code:

    Sub SendMessage(Optional AttachmentPath)
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim mNameSpace As Outlook.NameSpace

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


    With objOutlookMsg
    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("account@aol.com")
    objOutlookRecip.Type = olTo


    ' Set the Subject, Body, and Importance of the message.
    .Subject = "Test " & Now()
    .Body = "Test." & vbCrLf & vbCrLf
    .Importance = olImportanceHigh 'High importance

    ' Add attachments to the message.
    If Not IsMissing(AttachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    End If

    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    If Not objOutlookRecip.Resolve Then
    objOutlookMsg.Display
    End If
    Next

    End With
    objOutlookMsg.Send

    objOutlook.Quit
    Set objOutlookRecip = Nothing
    Set objOutlookAttach = Nothing
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing

    End Sub

  2. #2
    Join Date
    Sep 2006
    Posts
    3

    complile error now

    The problem is outlook is still sending the message when I quit the application. So I added this command.

    Form_CommandExecute (objOutlookMsg.Send).

    It calls the event procedure and displays a message after the command is done executing. But I am am getting a compile error on the .send saying function or variable name expected. Any ideas.

    Thanks

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I take it the docmd.sendobject wasn't a good solution for you? You can loop through a recipient list utilizing this command.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Sep 2006
    Posts
    3

    Thanks

    I'll try these suggestions. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •