dbTalk Databases Forums  

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

comp.databases.ms-access comp.databases.ms-access


Discuss send email using Outlook opens new session each time I send an email in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Filips Benoit
 
Posts: n/a

Default send email using Outlook opens new session each time I send an email - 10-18-2010 , 12:16 PM






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

Reply With Quote
  #2  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: send email using Outlook opens new session each time I send an email - 10-18-2010 , 05:00 PM






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

"Filips Benoit" <benoit.filips (AT) telenet (DOT) be> wrote

Quote:
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

Reply With Quote
  #3  
Old   
Filips Benoit
 
Posts: n/a

Default Re: send email using Outlook opens new session each time I send an email - 10-19-2010 , 02:32 AM



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 (AT) NOSPAM_gmail (DOT) com> wrote

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

"Filips Benoit" <benoit.filips (AT) telenet (DOT) be> wrote in message
news:Xj%uo.9360$HZ2.5190 (AT) newsfe30 (DOT) 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


Reply With Quote
  #4  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: send email using Outlook opens new session each time I send an email - 10-19-2010 , 05:39 PM



"Filips Benoit" <benoit.filips (AT) telenet (DOT) be> wrote

Quote:
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...

Reply With Quote
  #5  
Old   
Clif McIrvin
 
Posts: n/a

Default Re: send email using Outlook opens new session each time I send an email - 10-19-2010 , 06:08 PM



"Douglas J Steele" <NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote

Quote:
"Filips Benoit" <benoit.filips (AT) telenet (DOT) be> wrote in message
news:6Sbvo.7940$J84.7130 (AT) newsfe27 (DOT) 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?

Quote:
'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.)

Reply With Quote
  #6  
Old   
Filips Benoit
 
Posts: n/a

Default Re: send email using Outlook opens new session each time I send an email - 10-20-2010 , 05:14 AM



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 (AT) NOSPAM_gmail (DOT) com> wrote

Quote:
"Filips Benoit" <benoit.filips (AT) telenet (DOT) be> wrote in message
news:6Sbvo.7940$J84.7130 (AT) newsfe27 (DOT) 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...

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.