![]() |
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
|
|||
|
|||
![]()
Outlook Group:
Here is a simple program run from Microsoft Access that loops through the Outlook Inbox and moves the mail from the Inbox to one of two folders: "Saved Mail" or "Rejects". These are user folders at the same level as all the other standard folders.. (i.e. they are not underneath any of the standard folders). Each time it is run, it only moves one half of the items in the inbox. So, if there are 20 mails in the Inbox, and I run the program, it only moves 10 items to the user folders and leaves 10 still in the Inbox. If I run it a second time, then the inbox goes from 10 to 5. When I run it a third time, the inbox goes to 3. Next time, to 1. And finally all the mail is moved. It divides it in half each time. Unless I'm missing something, this bug is related to the fact that I'm moving items to a different folder. The bug DOES NOT OCCUR if I don't move the mail to another folder. Here's the code. Any comments would be appreciated. Option Compare Database Option Explicit Public Function IllustrateLoopBug() Dim OlApp As Outlook.Application Dim Inbox As Outlook.MAPIFolder Dim SavedMailFolder As Outlook.MAPIFolder Dim RejectMailFolder As Outlook.MAPIFolder Dim InboxItems As Outlook.Items Dim SavedMailItems As Outlook.MailItem Dim RejectMailItems As Outlook.MailItem Dim Mailobject As Object Dim intMailItems As Integer Dim intCountedLoops As Integer intCountedLoops = 0 Set OlApp = CreateObject("Outlook.Application") Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox) Set SavedMailFolder = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Parent.Folders("Saved Mail") Set RejectMailFolder = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Parent.Folders("Rejects") Set InboxItems = Inbox.Items intMailItems = InboxItems.Count intCountedLoops = 0 For Each Mailobject In InboxItems intCountedLoops = intCountedLoops + 1 If UCase(Left(Mailobject.Subject, 6)) "CLIENT" Then Mailobject.UnRead = False Set SavedMailItems = Mailobject.Move(RejectMailFolder) Else Mailobject.UnRead = False Set SavedMailItems = Mailobject.Move(SavedMailFolder) End If Next If intMailItems intCountedLoops Then MsgBox ("Mail Items = " & intMailItems & ", Counted Loops = " & intCountedLoops) End If Set OlApp = Nothing Set Inbox = Nothing Set SavedMailFolder = Nothing Set RejectMailFolder = Nothing Set InboxItems = Nothing Set SavedMailItems = Nothing Set RejectMailItems = Nothing Set Mailobject = Nothing End Function -- Rich Locus Logicwurks, LLC |
Ads |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Access Program Only Looping Part Way Through Outlook Inbox | Rich Locus | Outlook and VBA | 2 | May 8th 10 07:46 PM |
auto correct option under proof reading is not available to select | Pattigal | Outlook - Installation | 1 | April 14th 10 04:40 PM |
Looping thru Inbox | RS | Outlook and VBA | 1 | March 12th 08 06:41 AM |
Reading all messages from Inbox in Outlook using Mapi | uday | Outlook - Using Forms | 0 | May 8th 06 12:25 PM |
reading Outlook inbox in OE6 | MikeP | Outlook Express | 1 | January 24th 06 12:49 AM |