![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 11:12 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com