Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2014, 05:50 AM
Glenn_Suggs Glenn_Suggs is offline Processing Outlook emails items from Access Windows 7 64bit Processing Outlook emails items from Access Office 2010 32bit
Novice
Processing Outlook emails items from Access
 
Join Date: Jul 2013
Posts: 4
Glenn_Suggs is on a distinguished road
Question Processing Outlook emails items from Access


Hello. I'm having a problem getting Access to read through all items in the Outlook inbox. It appears to be getting all except the last item and then it stops the process all together. I'm using the For Each syntax like this:

Code:
Set InboxItems = Inbox.Items
For Each Mailobject in InboxItems
... do stuff with the current item
Next
As I said, it processes all items except the last one. Any ideas?
Thanks in advance.
Glenn
Reply With Quote
  #2  
Old 11-20-2014, 06:44 AM
gmayor's Avatar
gmayor gmayor is offline Processing Outlook emails items from Access Windows 7 64bit Processing Outlook emails items from Access Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following (processing from end to start):

Code:
Dim olApp As Object
Dim olNS As Object
Dim olItems As Object
Dim olItem As Object
Dim bStarted As Boolean
Dim i As Long

    On Error Resume Next

    Set olApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set olApp = CreateObject("Outlook.Application")
        bStarted = True
    End If
    On Error GoTo 0
    Set olNS = olApp.GetNamespace("MAPI")
    Set olItems = olNS.GetDefaultFolder(6).Items 'Default inbox
    For i = olItems.Count To 1 Step -1
        Set olItem = olItems(i)
        'Do stuff with olitem e.g.
        MsgBox olItem.Subject
    Next i

CleanUp:
    If bStarted = True Then
        olApp.Quit
    End If
    Set olApp = Nothing
    Set olNS = Nothing
    Set olItems = Nothing
    Set olItem = Nothing
lbl_Exit:
    Exit Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-20-2014, 08:35 AM
Glenn_Suggs Glenn_Suggs is offline Processing Outlook emails items from Access Windows 7 64bit Processing Outlook emails items from Access Office 2010 32bit
Novice
Processing Outlook emails items from Access
 
Join Date: Jul 2013
Posts: 4
Glenn_Suggs is on a distinguished road
Default

Thanks for the response. The code looks good and does make sense. Hopefully I can try it soon.... Glenn
Reply With Quote
Reply

Tags
email, inbox items, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Outlook emails items from Access Table in Mailmerge from selected items in access cnaab Mail Merge 1 11-01-2014 12:45 AM
Processing Outlook emails items from Access take emails from outlook mailbox and folders to Access megatronixs Outlook 6 10-23-2014 06:42 AM
Emails do not shoe in sent items asekely Outlook 0 07-26-2013 08:52 AM
Export Outlook emails to Access & parse certain text elements smahale Outlook 0 01-18-2012 09:30 PM
Outlook 2007 Saved sent items list only holds the last ten items david.peake Outlook 0 06-01-2010 07:27 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft