Help With Monitoring Inbox

  • Thread starter Thread starter Paul Schrader
  • Start date Start date
P

Paul Schrader

Hello,

I use the code below to monitor my inbox to move messages to particular
folders. The code works fine. What I need help with is the following

In outlook 2002 I have 2 inbox open at the same time , the primary is my
personal account ( Named Paul) and the secondary is an account( Named
Testing) that receive thousands of email a day. When I open outlook I need
to be able to have both accounts open so I can move back and forth between
the accts without having to log out and start a new outlook session and
select the acct to open. What I need help with is modifying the code below
to work on the Secondary acct(Named Testing) as the code currently only
appears to work on the Primary acct.


Any help would be appreciated

Thanks
Paul


Sub StartRule()
Dim objNameSpace As Outlook.NameSpace
Dim objInboxFolder As Outlook.MAPIFolder

Set objNameSpace = Application.Session
Set objInboxFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
Set objInboxItems = objInboxFolder.Items
'Set objDestinationFolder = objInboxFolder.Folders("Ndm Notifications")

End Sub

' Run this code to stop your rule.
Sub StopRule()
Set objInboxItems = Nothing
End Sub

' This code is the actual rule.
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

reg_Email



If Item.Subject = "Upload Confirmation" Then
Item.UnRead = False


Item.Move objDestinationFolder



End If
End Sub
 
Get the EntryID of the default Inbox. Iterate the Folders collection
of the NameSpace object and the subfolders until you get the other
Inbox.
 
Hello All,


Could someone provide an example on how to complete the task below that Ken
Suggests and then how to apply it to my existing code ?

Thanks
Paul
 
Here's a code snippet:

Dim sInboxID As String
Dim oFolder As Outlook.MAPIFolder
Dim oTest As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace
Dim oOL As Outlook.Application
Dim i As Long
Dim j As Long

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
sInboxID = oFolder.EntryID

j = oNS.Folders.Count
For i = 1 To j
Set oFolder = oNS.Folders(i)
For Each oTest In oFolder.Folders
If oTest.EntryID = sInboxID Then
'found it
End If
Next
Next i
 
Ken,

I'm not following you on this one, now that I have the Other SInboxid Value
what do I change in my existing Code Snippet Below to use this ? I tried
taking the value for the SInboxid from your code and using it in place of
the getdefaultfolder but that did not appear to help

Sorry if I missing something obvious ,I have tried several time using your
code snippet and cant figure out what I need to change in my code.

I Appreciate your Help !!!!

Paul
 
What problem are you having and what are you trying to do again? It
seems what you are doing now is different than the query that the code
snippet I posted is for.
 
Ken,

Listed Below is the Original Post for Help On this as well as your reply, I
look forward to you response .


Thanks
Paul

Ken Slovak - said:
Get the EntryID of the default Inbox. Iterate the Folders collection
of the NameSpace object and the subfolders until you get the other
Inbox.
 
The code snippet I posted will get you the secondary Inbox folder you
want. You just need to use that as your destination folder.
 
Ken,

I'm not getting this I tried he results from your snippet of code and tried
to apply it but with no luck

Can you show me what I need to change to make this work ? I run your code to
get the Id of the second mailbox and then qhat do I need to change in my
code to reference it ?

Thanks
Paul







Dim sInboxID As String
Dim oFolder As Outlook.MAPIFolder
Dim oTest As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace
Dim oOL As Outlook.Application
Dim i As Long
Dim j As Long

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
sInboxID = oFolder.EntryID

j = oNS.Folders.Count
For i = 1 To j
Set oFolder = oNS.Folders(i)
For Each oTest In oFolder.Folders
If oTest.EntryID = sInboxID Then
'found it
End If
Next
Next i
 
If you want to select an alternate Inbox to move messages to you can
find it using code similar to the code snippet I supplied. You can get
your default Inbox using NameSpace.GetDefaultFolder(olFolderInbox).
Each of those folders has an EntryID. You can assign a global
MAPIFolder object to the alternate Inbox folder when you find it or
you can store the EntryID of the folder and get it when you want using
NameSpace.GetItemFromID(strEntryID) where strEntryID is the EntryID
you stored.

Once you have the alternate folder and the default one you can move
items to the alternate folder.
 
Ken,

I want to monitor the Inbox of the Second Account. So that when New items
come in I can review them Programmatically to determine if they meet certain
criteria and deal with the Messages. I have the code that works fine when
only one inbox is open, but I need to be able to monitor a second inbox as
several of my users have 2 Inbox and what to run this code while having both
open.

Can you please review the code I've posted in this thread to determine if
their is a way to accomplish this ?

Thanks
Paul
 
I've been reviewing your code and posting hints for you all along. I
also don't respond to private emails, and delete them unread and never
send out receipts. It seems that you just want me to write your code
for you. Here is some sample code that monitors 2 different Inboxes.

Dim WithEvents objInboxItems As Outlook.Items
Dim WithEvents objAltInboxItems As Outlook.Items
Dim objDestinationFolder As Outlook.MAPIFolder

Sub StartRule()
Dim objNameSpace As Outlook.NameSpace
Dim objInboxFolder As Outlook.MAPIFolder
Dim strStoreID As String
Dim oFolder As Outlook.MAPIFolder
Dim oFolder1 As Outlook.MAPIFolder

On Error Resume Next

Set objNameSpace = Application.Session
Set objInboxFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
Set objInboxItems = objInboxFolder.Items
Set objDestinationFolder = objInboxFolder.Folders("Ndm
Notifications")

strStoreID = objInboxFolder.StoreID

For Each oFolder In objNameSpace.Folders
If oFolder.StoreID <> strStoreID Then
Set oFolder1 = oFolder.Folders("Testing")
If Not (oFolder1 Is Nothing) Then
Set objAltInboxItems = oFolder1.Items
Exit For
Else
Err.Clear
End If
End If
Next
End Sub

' Run this code to stop your rule.
Sub StopRule()
Set objInboxItems = Nothing
End Sub

' This code is the actual rule.
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim oItem As Outlook.MailItem

'Not sure what this is reg_Email

If Item.Subject = "Upload Confirmation" Then
Item.UnRead = False
Set oItem = Item.Move objDestinationFolder
End If
End Sub

Private Sub objAltInboxItems_ItemAdd(ByVal Item As Object)
Dim oItem As Outlook.MailItem

'Not sure what this is reg_Email

If Item.Subject = "Upload Confirmation" Then
Item.UnRead = False
Set oItem = Item.Move objDestinationFolder
End If
End Sub
 
Back
Top