send email using Outlook opens new session each time I send an email

  • Follow


Dear All,

Office 2010
Access 2010 but still using an mdb-file for the moment.

Outlook is running an minimized and should stay active !!!
Each time I send an email Outlook opens a new session!

I opens the current session with:  Set ObjOutlook = GetObject(, 
"Outlook.application")
and closes with objOutlook.Session.Logoff

I can't see why it creates a new session ?

Filip 


0
Reply Filips 10/18/2010 5:16:43 PM

Perhaps post the rest of your code. Perhaps you're inadvertently spawning 
another session somewhere.

"Filips Benoit" <benoit.filips@telenet.be> wrote in message 
news:Xj%uo.9360$HZ2.5190@newsfe30.ams2...
> Dear All,
>
> Office 2010
> Access 2010 but still using an mdb-file for the moment.
>
> Outlook is running an minimized and should stay active !!!
> Each time I send an email Outlook opens a new session!
>
> I opens the current session with:  Set ObjOutlook = GetObject(, 
> "Outlook.application")
> and closes with objOutlook.Session.Logoff
>
> I can't see why it creates a new session ?
>
> Filip
> 
0
Reply Douglas 10/18/2010 10:00:24 PM


The code !
------------------------------------------------------------------------------------------------------------------------------------------
Sub SendEmailNotVisible(EmailTo As String, Optional EmailSubject As String, 
Optional EmailBody As String, Optional AttachmentPath)

On Error GoTo errHandling

      Dim objOutlook As Outlook.Application
      Dim objOutlookMsg As Outlook.MailItem
      Dim objOutlookRecip As Outlook.Recipient
      Dim objOutlookAttach As Outlook.Attachment

    ' Get the Outlook session.
    Set objOutlook = GetObject(, "Outlook.Application")

      ' Create the message.
      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

      With objOutlookMsg
          ' Add the To recipient(s) to the message.
          'Set objOutlookMailTo = .Recipients.Add(EmailRecipient)
          'objOutlookRecip.Type = olTo
          .To = EmailTo

          ' Add the CC recipient(s) to the message.
          'Set objOutlookRecip = .Recipients.Add("nihil")
          'objOutlookRecip.Type = olCC

         ' Set the Subject, Body, and Importance of the message.
         If Not IsMissing(EmailSubject) Then .Subject = EmailSubject
         If Not IsMissing(EmailBody) Then .Body = EmailBody
         .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
        ' Next

         ' Sending
             .Send
      End With
    Set objOutlookAttach = Nothing
    Set objOutlookRecip = Nothing
    Set objOutlookMsg = Nothing

    objOutlook.Session.Logoff
    'objOutlook.Quit
    Set objOutlook = Nothing

Exit Sub

errHandling:
    objOutlookMsg.Close olDiscard
    Set objOutlookMsg = Nothing
    Set objOutlookAttach = Nothing
    Set objOutlookRecip = Nothing
    objOutlook.Quit
    Set objOutlook = Nothing
    MsgBox "Error in function SendEmailNotVisible: " & Err.Number & " " & 
Err.Description

End Sub

---------------------------------------
"Douglas J Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message 
news:i9ig1r$511$1@news.eternal-september.org...
> Perhaps post the rest of your code. Perhaps you're inadvertently spawning 
> another session somewhere.
>
> "Filips Benoit" <benoit.filips@telenet.be> wrote in message 
> news:Xj%uo.9360$HZ2.5190@newsfe30.ams2...
>> Dear All,
>>
>> Office 2010
>> Access 2010 but still using an mdb-file for the moment.
>>
>> Outlook is running an minimized and should stay active !!!
>> Each time I send an email Outlook opens a new session!
>>
>> I opens the current session with:  Set ObjOutlook = GetObject(, 
>> "Outlook.application")
>> and closes with objOutlook.Session.Logoff
>>
>> I can't see why it creates a new session ?
>>
>> Filip
>>
> 


0
Reply Filips 10/19/2010 7:32:22 AM

"Filips Benoit" <benoit.filips@telenet.be> wrote in message 
news:6Sbvo.7940$J84.7130@newsfe27.ams2...
> The code !
> ------------------------------------------------------------------------------------------------------------------------------------------
> Sub SendEmailNotVisible(EmailTo As String, Optional EmailSubject As 
> String, Optional EmailBody As String, Optional AttachmentPath)
>
> On Error GoTo errHandling
>
>      Dim objOutlook As Outlook.Application
>      Dim objOutlookMsg As Outlook.MailItem
>      Dim objOutlookRecip As Outlook.Recipient
>      Dim objOutlookAttach As Outlook.Attachment
>
>    ' Get the Outlook session.
>    Set objOutlook = GetObject(, "Outlook.Application")
>
>      ' Create the message.
>      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>
>      With objOutlookMsg
>          ' Add the To recipient(s) to the message.
>          'Set objOutlookMailTo = .Recipients.Add(EmailRecipient)
>          'objOutlookRecip.Type = olTo
>          .To = EmailTo
>
>          ' Add the CC recipient(s) to the message.
>          'Set objOutlookRecip = .Recipients.Add("nihil")
>          'objOutlookRecip.Type = olCC
>
>         ' Set the Subject, Body, and Importance of the message.
>         If Not IsMissing(EmailSubject) Then .Subject = EmailSubject
>         If Not IsMissing(EmailBody) Then .Body = EmailBody
>         .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
>        ' Next
>
>         ' Sending
>             .Send
>      End With
>    Set objOutlookAttach = Nothing
>    Set objOutlookRecip = Nothing
>    Set objOutlookMsg = Nothing
>
>    objOutlook.Session.Logoff
>    'objOutlook.Quit
>    Set objOutlook = Nothing
>
> Exit Sub
>
> errHandling:
>    objOutlookMsg.Close olDiscard
>    Set objOutlookMsg = Nothing
>    Set objOutlookAttach = Nothing
>    Set objOutlookRecip = Nothing
>    objOutlook.Quit
>    Set objOutlook = Nothing
>    MsgBox "Error in function SendEmailNotVisible: " & Err.Number & " " & 
> Err.Description
>
> End Sub

Hmm. I don't see anything there that looks amiss.

I do question why you are shutting down the session of Outlook if you want 
to use an active one... 

0
Reply Douglas 10/19/2010 10:39:05 PM

"Douglas J Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message 
news:i9l6md$ob4$1@news.eternal-september.org...
> "Filips Benoit" <benoit.filips@telenet.be> wrote in message 
> news:6Sbvo.7940$J84.7130@newsfe27.ams2...
>> The code !
>> ------------------------------------------------------------------------------------------------------------------------------------------
>> Sub SendEmailNotVisible(EmailTo As String, Optional EmailSubject As 
>> String, Optional EmailBody As String, Optional AttachmentPath)
>>
>> On Error GoTo errHandling
>>
>>      Dim objOutlook As Outlook.Application
>>      Dim objOutlookMsg As Outlook.MailItem
>>      Dim objOutlookRecip As Outlook.Recipient
>>      Dim objOutlookAttach As Outlook.Attachment
>>
>>    ' Get the Outlook session.
>>    Set objOutlook = GetObject(, "Outlook.Application")
>>
>>      ' Create the message.
>>      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>>
>>      With objOutlookMsg
>>          ' Add the To recipient(s) to the message.
>>          'Set objOutlookMailTo = .Recipients.Add(EmailRecipient)
>>          'objOutlookRecip.Type = olTo
>>          .To = EmailTo
>>
>>          ' Add the CC recipient(s) to the message.
>>          'Set objOutlookRecip = .Recipients.Add("nihil")
>>          'objOutlookRecip.Type = olCC
>>
>>         ' Set the Subject, Body, and Importance of the message.
>>         If Not IsMissing(EmailSubject) Then .Subject = EmailSubject
>>         If Not IsMissing(EmailBody) Then .Body = EmailBody
>>         .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
>>        ' Next
>>
>>         ' Sending
>>             .Send
>>      End With
>>    Set objOutlookAttach = Nothing
>>    Set objOutlookRecip = Nothing
>>    Set objOutlookMsg = Nothing
>>
>>    objOutlook.Session.Logoff
>>    'objOutlook.Quit
>>    Set objOutlook = Nothing
>>
>> Exit Sub
>>
>> errHandling:
>>    objOutlookMsg.Close olDiscard
>>    Set objOutlookMsg = Nothing
>>    Set objOutlookAttach = Nothing
>>    Set objOutlookRecip = Nothing
>>    objOutlook.Quit
>>    Set objOutlook = Nothing
>>    MsgBox "Error in function SendEmailNotVisible: " & Err.Number & " 
>> " & Err.Description
>>
>> End Sub
>
> Hmm. I don't see anything there that looks amiss.
>
> I do question why you are shutting down the session of Outlook if you 
> want to use an active one...


Perhaps the ( ' ) (ie, REM) here?

>>    'objOutlook.Quit

-- 
Clif McIrvin

Change nomail.afraid.org to gmail.com to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.) 


0
Reply clare.moe1 (2) 10/19/2010 11:08:28 PM

Before upgrating to Office 2010 in 2003 I used this code

Set objOutlook = CreateObject("Outlook.Application")
.....
objOutlook.Quit

It worked Ok in 2003 !!!
In 2010 it creates new session each time email-button is clicked!

Therefore I tried using

Set objOutlook = GetObject(, "Outlook.Application")
.............
objOutlook.Session.Logoff


Filip





"Douglas J Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message 
news:i9l6md$ob4$1@news.eternal-september.org...
> "Filips Benoit" <benoit.filips@telenet.be> wrote in message 
> news:6Sbvo.7940$J84.7130@newsfe27.ams2...
>> The code !
>> ------------------------------------------------------------------------------------------------------------------------------------------
>> Sub SendEmailNotVisible(EmailTo As String, Optional EmailSubject As 
>> String, Optional EmailBody As String, Optional AttachmentPath)
>>
>> On Error GoTo errHandling
>>
>>      Dim objOutlook As Outlook.Application
>>      Dim objOutlookMsg As Outlook.MailItem
>>      Dim objOutlookRecip As Outlook.Recipient
>>      Dim objOutlookAttach As Outlook.Attachment
>>
>>    ' Get the Outlook session.
>>    Set objOutlook = GetObject(, "Outlook.Application")
>>
>>      ' Create the message.
>>      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>>
>>      With objOutlookMsg
>>          ' Add the To recipient(s) to the message.
>>          'Set objOutlookMailTo = .Recipients.Add(EmailRecipient)
>>          'objOutlookRecip.Type = olTo
>>          .To = EmailTo
>>
>>          ' Add the CC recipient(s) to the message.
>>          'Set objOutlookRecip = .Recipients.Add("nihil")
>>          'objOutlookRecip.Type = olCC
>>
>>         ' Set the Subject, Body, and Importance of the message.
>>         If Not IsMissing(EmailSubject) Then .Subject = EmailSubject
>>         If Not IsMissing(EmailBody) Then .Body = EmailBody
>>         .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
>>        ' Next
>>
>>         ' Sending
>>             .Send
>>      End With
>>    Set objOutlookAttach = Nothing
>>    Set objOutlookRecip = Nothing
>>    Set objOutlookMsg = Nothing
>>
>>    objOutlook.Session.Logoff
>>    'objOutlook.Quit
>>    Set objOutlook = Nothing
>>
>> Exit Sub
>>
>> errHandling:
>>    objOutlookMsg.Close olDiscard
>>    Set objOutlookMsg = Nothing
>>    Set objOutlookAttach = Nothing
>>    Set objOutlookRecip = Nothing
>>    objOutlook.Quit
>>    Set objOutlook = Nothing
>>    MsgBox "Error in function SendEmailNotVisible: " & Err.Number & " " & 
>> Err.Description
>>
>> End Sub
>
> Hmm. I don't see anything there that looks amiss.
>
> I do question why you are shutting down the session of Outlook if you want 
> to use an active one...
> 


0
Reply Filips 10/20/2010 10:14:00 AM

5 Replies
370 Views

(page loaded in 0.073 seconds)

Similiar Articles:













7/27/2012 4:17:01 PM


Reply: