Code misses some new items in InBox 
Author Message
 Code misses some new items in InBox

I am attempting to automate the saving of attachments and emails from
certain senders.  I am using Redemption to get arround Outlook's
security feature/bug.  If multiple emails arrive at one time, the code
will only process the first one.  I am using code (listed below) that
I cobbled together from some of Sue Mosher's articles, Redemptions'
documentation, and my experimentation.

What I am doing wrong?  Any help is greatly appreciated, this is my
first attempt at VB programing in Outlook.    Mike

Dim WithEvents objInBox As Outlook.Items

Private Sub Application_Startup()
    Set objInBox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Sub objInbox_ItemAdd(ByVal Item As Object)
    Set myOlApp = CreateObject("Outlook.Application")
    Set myFolders = _
     myOlApp.ActiveExplorer.CurrentFolder.Folders
    Dim SafeItem, oItem
    Set SafeItem = CreateObject("Redemption.SafeMailItem")
    SafeItem.Item = Item
         If SafeItem.Class = olMail And SafeItem.SenderName = "Chad
Roemig" And
         InStr(SafeItem.Subject, "Message Center Daily Report") > 0
And _
         SafeItem.Attachments.Count > 0 Then
            Dim objAttachments As Outlook.Attachments
            Set objAttachments = SafeItem.Attachments
            For Each objAttach In objAttachments
                objAttach.SaveAsFile "D:\Traffic\CDR\VML\MCDR" & _
                 Format(Mid(SafeItem.Subject, InStr(25,
SafeItem.Subject, " ",_
                   1) + 1, 10), "yymmdd") & ".xls"
            Next
            Set objAttachments = Nothing
            SafeItem.Delete
        ElseIf SafeItem.Class = olMail And InStr(SafeItem.SenderName,
_
         "SCS reporting user") > 0 And _
         InStr(SafeItem.Subject, "Daily ACD Pegging Group Call Type
Report") > _
          0 And SafeItem.Attachments.Count = 0 Then
            SafeItem.SaveAs "D:\Traffic\CDR\VML\PGCR" & _
             Format(Right(SafeItem.Subject, 10), "yymmdd") & ".txt",
olTXT
            SafeItem.UnRead = False
            SafeItem.Delete
        End If
 end sub



Mon, 01 Aug 2005 21:42:38 GMT  
 Code misses some new items in InBox
ItemAdd is buggy when a lot of emails arrive at the same time. The
best you can do is minimize the code that runs in the event handler so
you don't spend a lot of time in that event.

Don't create an Outlook object in that event, that's time consuming.
If you aren't running in Outlook VBA use a pre-created
Outlook.Application object. Same for the Redemption object. Test for
the Class and Subject before you assign the item to a SafeItem, that's
also a time consuming thing.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> I am attempting to automate the saving of attachments and emails
from
> certain senders.  I am using Redemption to get arround Outlook's
> security feature/bug.  If multiple emails arrive at one time, the
code
> will only process the first one.  I am using code (listed below)
that
> I cobbled together from some of Sue Mosher's articles, Redemptions'
> documentation, and my experimentation.

> What I am doing wrong?  Any help is greatly appreciated, this is my
> first attempt at VB programing in Outlook.    Mike

> Dim WithEvents objInBox As Outlook.Items

> Private Sub Application_Startup()
>     Set objInBox = Session.GetDefaultFolder(olFolderInbox).Items
> End Sub

> Sub objInbox_ItemAdd(ByVal Item As Object)
>     Set myOlApp = CreateObject("Outlook.Application")
>     Set myFolders = _
>      myOlApp.ActiveExplorer.CurrentFolder.Folders
>     Dim SafeItem, oItem
>     Set SafeItem = CreateObject("Redemption.SafeMailItem")
>     SafeItem.Item = Item
>          If SafeItem.Class = olMail And SafeItem.SenderName = "Chad
> Roemig" And
>          InStr(SafeItem.Subject, "Message Center Daily Report") > 0
> And _
>          SafeItem.Attachments.Count > 0 Then
>             Dim objAttachments As Outlook.Attachments
>             Set objAttachments = SafeItem.Attachments
>             For Each objAttach In objAttachments
>                 objAttach.SaveAsFile "D:\Traffic\CDR\VML\MCDR" & _
>                  Format(Mid(SafeItem.Subject, InStr(25,
> SafeItem.Subject, " ",_
>                    1) + 1, 10), "yymmdd") & ".xls"
>             Next
>             Set objAttachments = Nothing
>             SafeItem.Delete
>         ElseIf SafeItem.Class = olMail And

InStr(SafeItem.SenderName,

- Show quoted text -

Quote:
> _
>          "SCS reporting user") > 0 And _
>          InStr(SafeItem.Subject, "Daily ACD Pegging Group Call Type
> Report") > _
>           0 And SafeItem.Attachments.Count = 0 Then
>             SafeItem.SaveAs "D:\Traffic\CDR\VML\PGCR" & _
>              Format(Right(SafeItem.Subject, 10), "yymmdd") & ".txt",
> olTXT
>             SafeItem.UnRead = False
>             SafeItem.Delete
>         End If
>  end sub



Tue, 02 Aug 2005 23:51:42 GMT  
 Code misses some new items in InBox
Once solution that Dmitry suggested (and I haven't had time to test) is to use Redemption's NewMail event to build a list of EntryIDs for incoming items, then have another process taking care of those as time permits.


Quote:
> ItemAdd is buggy when a lot of emails arrive at the same time. The
> best you can do is minimize the code that runs in the event handler so
> you don't spend a lot of time in that event.

> Don't create an Outlook object in that event, that's time consuming.
> If you aren't running in Outlook VBA use a pre-created
> Outlook.Application object. Same for the Redemption object. Test for
> the Class and Subject before you assign the item to a SafeItem, that's
> also a time consuming thing.

> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Lead Author, Beginning VB 6 Application Development, Wrox Press
> Attachment Options
> http://www.slovaktech.com/attachmentoptions.htm
> Extended Reminders
> http://www.slovaktech.com/extendedreminders.htm



> > I am attempting to automate the saving of attachments and emails
> from
> > certain senders.  I am using Redemption to get arround Outlook's
> > security feature/bug.  If multiple emails arrive at one time, the
> code
> > will only process the first one.  I am using code (listed below)
> that
> > I cobbled together from some of Sue Mosher's articles, Redemptions'
> > documentation, and my experimentation.

> > What I am doing wrong?  Any help is greatly appreciated, this is my
> > first attempt at VB programing in Outlook.    Mike

> > Dim WithEvents objInBox As Outlook.Items

> > Private Sub Application_Startup()
> >     Set objInBox = Session.GetDefaultFolder(olFolderInbox).Items
> > End Sub

> > Sub objInbox_ItemAdd(ByVal Item As Object)
> >     Set myOlApp = CreateObject("Outlook.Application")
> >     Set myFolders = _
> >      myOlApp.ActiveExplorer.CurrentFolder.Folders
> >     Dim SafeItem, oItem
> >     Set SafeItem = CreateObject("Redemption.SafeMailItem")
> >     SafeItem.Item = Item
> >          If SafeItem.Class = olMail And SafeItem.SenderName = "Chad
> > Roemig" And
> >          InStr(SafeItem.Subject, "Message Center Daily Report") > 0
> > And _
> >          SafeItem.Attachments.Count > 0 Then
> >             Dim objAttachments As Outlook.Attachments
> >             Set objAttachments = SafeItem.Attachments
> >             For Each objAttach In objAttachments
> >                 objAttach.SaveAsFile "D:\Traffic\CDR\VML\MCDR" & _
> >                  Format(Mid(SafeItem.Subject, InStr(25,
> > SafeItem.Subject, " ",_
> >                    1) + 1, 10), "yymmdd") & ".xls"
> >             Next
> >             Set objAttachments = Nothing
> >             SafeItem.Delete
> >         ElseIf SafeItem.Class = olMail And
> InStr(SafeItem.SenderName,
> > _
> >          "SCS reporting user") > 0 And _
> >          InStr(SafeItem.Subject, "Daily ACD Pegging Group Call Type
> > Report") > _
> >           0 And SafeItem.Attachments.Count = 0 Then
> >             SafeItem.SaveAs "D:\Traffic\CDR\VML\PGCR" & _
> >              Format(Right(SafeItem.Subject, 10), "yymmdd") & ".txt",
> > olTXT
> >             SafeItem.UnRead = False
> >             SafeItem.Delete
> >         End If
> >  end sub



Wed, 03 Aug 2005 06:28:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Missed New Mail/Inbox Items Add Events

2. How do i find all items from a person in inbox by code

3. Creating New menu and sub menu items all through code

4. New menu item with code

5. Inbox right click menu item

6. Where are saved the rules of inbox items in outlook

7. Setting Inbox to process mail items

8. Changing display font of Inbox item

9. Permanently delete item from Inbox in Outlook VBA

10. Problem with REPORT.IPM.Note.IPNRN items when Iterating Through Inbox

11. Get Currently Selected Inbox Item

12. Extracting the Internet Email Address from Inbox Items

 

 
Powered by phpBB® Forum Software