[dba-Tech] Sensing email items in an outlook folder

John Colby jwcolby at ColbyConsulting.com
Sun Jan 8 10:24:14 CST 2006


The following code was working in an Access project for sensing messages in
a folder and processing the email.  I am trying to build a little
application for preparing my spam to be sent off to BlueFrog for reporting.
The code is not working from directly inside of Outlook.  The code gets
here, but the Items collection never contains anything, even when there is
email in the folder.  Any ideas?

Function CheckForSpamMail(fldrSpamIncoming As Outlook.MAPIFolder) As Boolean
On Error GoTo Err_CheckForSpamMail
Dim msg As Outlook.MailItem
    Debug.Print fldrSpamIncoming.Name
    For Each msg In fldrSpamIncoming.Items
        Debug.Print "CheckForSpamMail - Processing message #" & intMsgCnt; "
of " & fldrSpamIncoming.Items.Count
        ProcessSpamMail fldrSpamIncoming, msg
    Next msg
'    intMsgCntOrig = fldrSpamIncoming.Items.Count
'    For intMsgCnt = 1 To intMsgCntOrig
'        Set msg = fldrSpamIncoming.Items(1)
'        Debug.Print "CheckForSpamMail - Processing message #" & intMsgCnt;
" of " & fldrSpamIncoming.Items.Count
'        ProcessSpamMail fldrSpamIncoming, msg
'    Next intMsgCnt
    
Exit_CheckForSpamMail:
On Error Resume Next
    Set msg = Nothing
Exit Function
Err_CheckForSpamMail:
    Select Case Err
    Case 0      '.insert Errors you wish to ignore here
        Resume Next
    Case -2147352567 'No messages
        Resume Exit_CheckForSpamMail
    Case Else   '.All other errors will trap
        Beep
        MsgBox Err.Number & ":" & Err.Description, , "Error in Function
dclsOutlook.CheckForSpamMail"
        Resume Exit_CheckForSpamMail
    End Select
    Resume 0    '.FOR TROUBLESHOOTING
End Function

John W. Colby
www.ColbyConsulting.com 





More information about the dba-Tech mailing list