A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook staying in memory



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 12th 09, 08:26 AM posted to microsoft.public.office.developer.outlook.vba,microsoft.public.outlook.program_vba
Rod[_5_]
external usenet poster
 
Posts: 2
Default Outlook staying in memory

I am running a VBA program in Access to send emails. The email is sent OK
but Outlook stays in memory.
In the code below I have put in a message box to slow the code down. If this
is there then Outlook correctly closes itself down.
Because it is not closed it creates problems the next time I call the code,
even if it is modified to pick up an already open version of outlook.

I am using Office 2002 on a Vista machine with several cpus

Any suggestions please

many thanks


--------------------------------


Public Sub Create_eMails()

Dim olApp As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim OBmailItem As Outlook.MailItem

Set olApp = New Outlook.Application

Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon ""

Set OBmailItem = olApp.CreateItem(olMailItem)

OBmailItem.To = "

OBmailItem.Subject = "Test Email. "
OBmailItem.Body = "Test Body Text "
OBmailItem.Send

Call MsgBox("Wait")

olNs.Logoff

olApp.Quit

Set OBmailItem = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub


Ads
  #2  
Old June 12th 09, 02:00 PM posted to microsoft.public.office.developer.outlook.vba,microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Outlook staying in memory

You need to allow time for the send operation to finish. You can try using a
DoEvents() call, but I don't think that will do it. Best thing to do
probably is to start a Send/Receive operation and wait for that to finish.
If you get a handle to SyncObjects(1) and call that SyncObject's Start()
method with an event handler for SyncEnd that should do it:

Dim WithEvents synch As Outlook.SyncObject ' in a class that can handle
events
Dim blnFinished As Boolean

When you call send you then use this:

blnFinished = False
Set synch = olNS.SyncObjects.Item(1)
synch.Start

While blnFinished = False
DoEvents
Loop

Your handler would look like this:

Private Sub synch_SyncEnd()
blnFinished = True
End Sub

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rod" wrote in message
...
I am running a VBA program in Access to send emails. The email is sent OK
but Outlook stays in memory.
In the code below I have put in a message box to slow the code down. If
this is there then Outlook correctly closes itself down.
Because it is not closed it creates problems the next time I call the
code, even if it is modified to pick up an already open version of
outlook.

I am using Office 2002 on a Vista machine with several cpus

Any suggestions please

many thanks


--------------------------------


Public Sub Create_eMails()

Dim olApp As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim OBmailItem As Outlook.MailItem

Set olApp = New Outlook.Application

Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon ""

Set OBmailItem = olApp.CreateItem(olMailItem)

OBmailItem.To = "

OBmailItem.Subject = "Test Email. "
OBmailItem.Body = "Test Body Text "
OBmailItem.Send

Call MsgBox("Wait")

olNs.Logoff

olApp.Quit

Set OBmailItem = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub


  #3  
Old June 12th 09, 02:55 PM posted to microsoft.public.office.developer.outlook.vba,microsoft.public.outlook.program_vba
Rod[_5_]
external usenet poster
 
Posts: 2
Default Outlook staying in memory

Thanks, I give it a go, I've never played with evens before.



"Ken Slovak - [MVP - Outlook]" wrote in message
...
You need to allow time for the send operation to finish. You can try using
a DoEvents() call, but I don't think that will do it. Best thing to do
probably is to start a Send/Receive operation and wait for that to finish.
If you get a handle to SyncObjects(1) and call that SyncObject's Start()
method with an event handler for SyncEnd that should do it:

Dim WithEvents synch As Outlook.SyncObject ' in a class that can handle
events
Dim blnFinished As Boolean

When you call send you then use this:

blnFinished = False
Set synch = olNS.SyncObjects.Item(1)
synch.Start

While blnFinished = False
DoEvents
Loop

Your handler would look like this:

Private Sub synch_SyncEnd()
blnFinished = True
End Sub

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rod" wrote in message
...
I am running a VBA program in Access to send emails. The email is sent OK
but Outlook stays in memory.
In the code below I have put in a message box to slow the code down. If
this is there then Outlook correctly closes itself down.
Because it is not closed it creates problems the next time I call the
code, even if it is modified to pick up an already open version of
outlook.

I am using Office 2002 on a Vista machine with several cpus

Any suggestions please

many thanks


--------------------------------


Public Sub Create_eMails()

Dim olApp As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim OBmailItem As Outlook.MailItem

Set olApp = New Outlook.Application

Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon ""

Set OBmailItem = olApp.CreateItem(olMailItem)

OBmailItem.To = "

OBmailItem.Subject = "Test Email. "
OBmailItem.Body = "Test Body Text "
OBmailItem.Send

Call MsgBox("Wait")

olNs.Logoff

olApp.Quit

Set OBmailItem = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub





 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Other Calendars not staying Noel Outlook - Calandaring 3 June 23rd 08 05:06 PM
Sent messages staying in outbox... Mike Outlook - General Queries 1 June 29th 07 06:18 PM
2 GB of memory over 1 GB of memory free, and outlook complains of being out of memory David Hettel Outlook Express 7 October 18th 06 12:08 PM
messages staying in ouitbox Idot Outlook - General Queries 2 August 29th 06 08:50 PM
Outlook Not Closing - Staying in System Tray Alan W Outlook - Installation 1 August 8th 06 08:13 PM


All times are GMT +1. The time now is 10:33 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.