Limitation with ActiveExplorer Selection?

R

Rafael

I'm trying to iterate through a few hundred contacts item on a PF (Exchange
2003 running on Windows Server 2003 and OL XP SP2) but everytime I select
too many contacts, the application fails with: Run-time error
'-1456455675(a9304005)';.

This VBA code works fine with around 100 contacts or less. I've tried the
same thing with a VB 6.0 app and the result is the same.

I wondering if there's a limitation of memory or something that does not
allow me to get the count of a couple of hundreds contact records?


Dim myolapp As Outlook.Application
Set myolapp = CreateObject("Outlook.Application")
Dim NS As Outlook.NameSpace
Set NS = myolapp.GetNamespace("MAPI")
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myItems As Outlook.Items
Dim AllPublicFolders As MAPIFolder
Dim myFolder As Outlook.Folders

Dim myContact As ContactItem
Set myOlExp = myolapp.ActiveExplorer

Set myOlSel = myOlExp.Selection
MsgBox myOlSel.Count

Thanks,

Rafael
 
T

Tom Rizzo [MSFT]

I believe the selection collection is limited in the number of items you can
select. Can't remember the limit right now but 100's may be too much for
it.

Tom
 
R

Rafael

The code I'm using is shown below (bottom of this email)....

It will not dispaly the number of contacts selected.

Thanks,

Rafael

John Riddle said:
I'm able to do this just fine. Is the code you are providing not
displaying the selection count?
 
R

Rafael

You're correct John, I do want to iterate through the selection and read
data (email address) from each contact item. The problem is that the
application does not allow me to select more than a screen or two worth of
contacts.

Any how, I copy and pasted your code as shown below and selected about 8
screens worth of items and the I got the following error message:
run time error: 72874393(d4904005) and when I went to debug, the selection
expression (Set mySelection = myExplorer.Selection) had the message when I
put the mouse over it: "the messaging interface has returned an unknown
error".

Thanks,

Rafael

John Riddle said:
I saw your code for the message box, but you had Dim'd Folders,
ContactItem, Items, etc. I thought you must be wanting to do something more
than just get the count of selected items (such as iterate through the items
and make changes?)
 
J

John Riddle

That's strange. I don't know what could be causing that. I use this function everyday to get the number of items after I have set a filter on the folder. The listing in the bottom left hand corner of Outlook simply tells you the total number of items in a folder and that a filter is applied. Once I apply my filter, I very often want to know how many items are visible. Therefore, I select all items and use this function to tell me how many I have after the filter. I've never had a problem.

It could be a bug in your version of Outlook.

John
 
K

Ken Slovak - [MVP - Outlook]

I vaguely recall a limitation of a hundred or so selected items and
exceeding that causing problems when reading Selection but I couldn't find a
KB on the problem when I looked and I seem to recall last discussing the
problem during the Outlook 2000 beta so it's all in a fog by now.




John Riddle said:
That's strange. I don't know what could be causing that. I use this
function everyday to get the number of items after I have set a filter on
the folder. The listing in the bottom left hand corner of Outlook simply
tells you the total number of items in a folder and that a filter is
applied. Once I apply my filter, I very often want to know how many items
are visible. Therefore, I select all items and use this function to tell me
how many I have after the filter. I've never had a problem.
 
K

Ken Slovak - [MVP - Outlook]

There are a lot of factors involved, such as system resources and overall
RAM and virtual memory size. I've seen loops that worked correctly on my dev
machines cause out of memory errors on client's machines because of that.
There's a long-standing bug in how Outlook handles iterating collections of
items in loops. It creates internal variables that aren't released until
after the procedure exits and it gets worse the more dot operators you use,
since Outlook creates internal variables for each suboperator in the dots.
That's why using CDO 1.21 code works for loops like that, it doesn't create
those internal variables and can handle looping over much larger collections
than Outlook code can.

As far as specific limits on Selection, there aren't any hard and fast
rules. It just seems to break at some point.




John Riddle said:
In my version of Outlook (2003), when I select a large number of items for
processing, I generally run into memory problems after a couple hundred or
so. However, I can very easily select several thousand and get a count
(Selection.Count). I can't understand at all why he would be having a
problem with that.
Also, even if I only select a few dozen at a time and loop through them
with a For...Next loop such as:
Dim candFolder As MAPIFolder
Set candFolder = Application.ActiveExplorer.CurrentFolder
If candFolder.DefaultItemType = olContactItem Then
strJobTitle = "Manager"
strDepartment = "IT"
For Each cand In Application.ActiveExplorer.Selection
cand.JobTitle = strJobTitle
cand.Department = strDepartment
cand.Save
Set cand = Nothing
Next
strJobTitle = ""
strDepartment = ""
End If
Set candFolder = Nothing

This code produces "Out of memory." errors if more than a couple hundred
items are selected AND oddly enough, if I select only a couple dozen and
process them, then select a couple dozen different items and process them
and so on in stages like this, I still get memory errors after a few
hundred. I'm convinced that processing items using the Selection collection
has memory problems.
 
R

Rafael

Ken - Group,

BTW: I have a Windows XP SP1+ PC with 512 MB of RAM running on a P4 2Ghtz
The problem occurs with both my VB application and when I use VBA.

If any of you have a CDO code I to get the count at least I would like to
try it and see how that works. The other variable I want throw in the mix
is the fact that I am using custom Oulook forms for my contacts on the
Public Folders.

Thanks for your help on this issue.

Rafael
 
K

Ken Slovak - [MVP - Outlook]

CDO doesn't know anything about Outlook Explorers, the UI or selections so
CDO can't help with that. Iterating large collections with CDO is what is
faster and handles more items.
 
R

Rafael

CDO is something I need to do some work on so if there's a code out there
that I can use I would appreciate it.

Thanks,

Rafael
 

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