#1
|
|||
|
|||
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 Thanks in advance. Glenn |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
Thanks for the response. The code looks good and does make sense. Hopefully I can try it soon.... Glenn
|
Tags |
email, inbox items, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Table in Mailmerge from selected items in access | cnaab | Mail Merge | 1 | 11-01-2014 12:45 AM |
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 |