Cannot access more than 250 items in a folder

J

John Gordon

My company has a custom Outlook form for handling vacation and sick time
requests. The form has fields for start date/time, end date/time, name,
etc.

I'm trying to write some code that will process a bunch of saved requests
and display some totals, but I'm having trouble. The code simply stops
working after about the 250th item in a folder. Any attempt to get at
the custom properties of any item after the 250th is a blank.

Here's some very simple code I wrote to illustrate the problem. It loops
through each saved item and checks if the "requestor" property contains
a capital I. (Our organization has a capital I in the name, and the org
name is appended to everyone's name, so everyone effectively has a capital
I in their name.)

The result of the code *should* be one capital I for every item in the
folder, but it ain't working that way. After about item 247 or so, it
stops working. No further items will register as containing a capital I
in the "requestor" property.

I've found various vague references claiming that this is a known bug,
that you cannot access more than 250 items in a folder, but that seems
preposterous. There must be a way around it.

Can anyone help? Thanks.

Code follows -------------------------------------

Option Explicit

Dim objapp, curr_fldr

Set objapp = CreateObject("Outlook.Application")
Set curr_fldr = objapp.ActiveExplorer.Currentfolder

Sub btnReport_Click()
Dim requestor, itm, itemNumber, Icount, tmpIcount, theLength
Dim idx, myChar, noIcount

On Error Resume Next

Icount = 0
noIcount = 0

For itemNumber = 1 to curr_fldr.Items.Count
Set itm = curr_fldr.Items(itemNumber)
requestor = " "
requestor = itm.UserProperties("Requestor")
theLength = Len(requestor)
tmpIcount = 0
For idx = 1 to theLength
myChar = Mid(requestor, idx, 1)
if myChar = "I" Then
tmpIcount = tmpIcount + 1
End If
Next
if tmpIcount = 0 then
noIcount = noIcount + 1
end if
Icount = Icount + tmpIcount
Set itm = Nothing
Next

MsgBox "Finished reading messages" & vbCrLf & "Icount = " & Icount _
& vbCrLf & "noIcount = " & noIcount
End Sub

Code ends -------------------------------------
 
B

Ben M. Schorr - MVP

Just a suggestion - you may want to post this in the
Microsoft.public.outlook.program_vba newsgroup. A lot of the coding experts
hang out in there.

Aloha,

-Ben-
Ben M. Schorr, OneNote-MVP
Roland Schorr & Tower
http://www.rolandschorr.com
Microsoft Outlook FAQ: http://www.factplace.com/outlook.htm

**I apologize but I am unable to respond to direct requests for assistance.
Please post questions and replies here in the newsgroup. Mahalo!
 
J

John Gordon

In said:
Just a suggestion - you may want to post this in the
Microsoft.public.outlook.program_vba newsgroup. A lot of the coding experts
hang out in there.

I'll do that. Thanks.
 
K

Ken Slovak - [MVP - Outlook]

There's a limit of roughly 256 RPC connections for Exchange server by
default and you are running into that. Don't use For Each loops, use For i =
type loops and release your objects each pass through the loop. Also, you
can change the RPC channel limit with a registry change on the server. See
the information at MSDN about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top