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

Proof Of Looping Bug in Reading Outlook Inbox From Access?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 8th 10, 07:09 PM posted to microsoft.public.outlook.program_vba
Rich Locus
external usenet poster
 
Posts: 8
Default Proof Of Looping Bug in Reading Outlook Inbox From Access?

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
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
Access Program Only Looping Part Way Through Outlook Inbox Rich Locus Outlook and VBA 2 May 8th 10 06:46 PM
auto correct option under proof reading is not available to select Pattigal Outlook - Installation 1 April 14th 10 03:40 PM
Looping thru Inbox RS Outlook and VBA 1 March 12th 08 05:41 AM
Reading all messages from Inbox in Outlook using Mapi uday Outlook - Using Forms 0 May 8th 06 11:25 AM
reading Outlook inbox in OE6 MikeP Outlook Express 1 January 23rd 06 11:49 PM


All times are GMT +1. The time now is 04:48 AM.


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