![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |