PDA

View Full Version : Running a module on a loop



jessmith07
02-24-2012, 08:44 AM
I am trying to create a way to capture all incoming emails (Outlook 2007) to a "customer support" inbox and save them to a folder on a network drive.

I have successfully used the code from the following KB article:

Save Emails From Outlook To Hard Drive

Now what I'd like to do is have this run on a loop so that any new incoming email will be added as well, including emails moved to subfolders.

Is there a way to do this?

Can this be done through Access by calling the procedure? (I'm thinking of creating a database to manage all of this).

Thank you.

JP2112
03-14-2012, 06:42 AM
Would you please post a link to the KB entry, I can't find it. If you cannot post a link just post the KB number.

jessmith07
03-15-2012, 12:17 PM
It doesn't say what the article number is, but the number at the end of the link is kb_id=875

JP2112
03-16-2012, 07:47 AM
For reference here is the link: http://www.vbaexpress.com/kb/getarticle.php?kb_id=875

I think all you would need to do is use an event handler and call SaveAllEmails_ProcessAllSubFolders in it. Instead of using PickFolder, just point to the default Inbox.

ex:


Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)
On Error Goto ErrorHandler

If TypeName(item) = "MailItem" Then
SaveAllEmails_ProcessAllSubFolders
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub