Parculiar loop behaviour

Posted on 2003-03-23
Medium Priority
Last Modified: 2010-04-07
Following on from my last question about referencing Inbox sub-folders, I have noticed that the VB loop that contains the code that deals with the Inbox emails and the subfolders is not dealing with all the emails in the Inbox. The loop is exited once 50% of the Inbox emails have been processed, rounded up. The code loop is as follows:

    For Each oMsg In oFolder.Items ' Emails in Inbox
       ' many lines of email action code
    Next ' messages

The code within the for/next loop does not jump to other routines except to write to a log file, and there are no early exit statements. oMsg is declared as an Object and oFolder is declared as a Variant. The Outlook linkage is as follows:
    Set oApp = CreateObject("Outlook.Application")
    Set oNS = oApp.GetNamespace("MAPI")
    'Set folder to check the INBOX
    Set oFolder = oNS.GetDefaultFolder(olFolderInbox)

Any ideas why the loop should be exited at 50% of Inbox messages processed?

Question by:vbmds
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Accepted Solution

stefri earned 150 total points
ID: 8216252
did you try to assign oFolder.Items to a temp variable ?
set inItems = oFolder.Items

for each oMsg in inItems


or you could try:

itCount = oFolder.Items.count

for i = itCount to 1 step -1


oFolder could be declared as MapiFolder

Author Comment

ID: 10489404
Sorry, must have overlooked the response notification about stefri's response. I have endup using the forced loop method to control the function.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question