Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine two inbox's items to be processed by one For Each loop

Status
Not open for further replies.

lamarw

MIS
Dec 18, 2002
223
US
Hello everyone!
I'm having trouble with something that I cannot resolve. It has to do with outlook.application
What I would like to do is combine the contents of two different in boxes (AInbox and BInbox) such that a 'For Each' statement can process the contents of both as one box.

Set AInbox = OlApp.GetNamespace("MAPI").Folders("Personal Folders"). ...etc to A box name
Set BInbox = OlApp.GetNamespace("MAPI").Folders("Personal Folders"). ...etc to B different box name
Set AInboxItems = AInbox.items.Restrict("[Unread] = true")
Set BInboxItems = BInbox.items.Restrict("[Unread] = true")

' I have been processing mailitems with a single For Each ... loop which is working fine
For Each MailObject In AInboxItems

However, now I need to do something such as:
CombinedInboxItems = AInboxItems + BInboxItems '(This is probably bad syntax but it illustrates my intent)

'Then within a single For Each loop
For Each MailObject In CombinedInboxItems

Any ideas would be very much appreciated.

Lamar
 
Why not simply do 2 For Each loop ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya lamarw . . .

Why not use a [blue]For Next[/blue] loop with an index variable? Although you'd still have to address both outlook objects. Something like:
Code:
[blue]For x = 1 to maxcount
   strVariableA = AInboxItems(x)
   strVariableB = BInboxItems(x)
Next[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
You need two for loops as PHV as noted but what you can do is make a procedure or function that takes mailitem byref.... Then you are still maintaining your code in one place.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top