A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Access Program Only Looping Part Way Through Outlook Inbox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 7th 10, 09:43 PM posted to microsoft.public.outlook.program_vba
Rich Locus
external usenet poster
 
Posts: 8
Default Access Program Only Looping Part Way Through Outlook Inbox

Hello Outlook Group:

I am developing an Access application that reads through the Inbox (both
read and unread mail), and under certain conditions, adds the mail
information to an Access database. When I am done looking at the mail item,
I file it one one of two folders: either REJECTS or SAVED MAIL. I'm using
POP3.

The problem is that it only loops about half-way through the inbox and exits
BEFORE all the mail in the inbox folder is processed. I have two sub-folders
under the inbox, one call REJECTS and the other SAVED MAIL.

If I do a ? InboxItems.COUNT, the count of the mail is correct... i.e. it
will say I have 7 emails, and that's the correct number, but it only loops
through about 4 times instead of 7 and leaves mail in the INBOX. The code
follows. Any ideas?

Option Compare Database
Option Explicit

Public Function ReadInboxAndMoveV1()
Dim TempRst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim SavedMailFolder As Outlook.MAPIFolder
Dim RejectMailFolder As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim SavedMailItems As Outlook.MailItem
Dim RejectMailItems As Outlook.MailItem
Dim Mailobject As Object
Dim db As DAO.Database

DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from tbl_outlooktemp"
DoCmd.SetWarnings True
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox)
Set SavedMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Saved
Mail")
Set RejectMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Rejects")
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
'
Set InboxItems = Inbox.Items
'
For Each Mailobject In InboxItems
If UCase(Left(Mailobject.Subject, 6)) "CLIENT" Then
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(RejectMailFolder)
Else
With TempRst
.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(SavedMailFolder)
End With
End If
Next

Set TempRst = Nothing
Set OlApp = Nothing
Set Inbox = Nothing
Set SavedMailFolder = Nothing
Set InboxItems = Nothing
Set SavedMailItems = Nothing
Set Mailobject = Nothing

End Function

Any help would be appreciated!!!
--
Rich Locus
Logicwurks, LLC
Ads
  #2  
Old May 7th 10, 10:04 PM posted to microsoft.public.outlook.program_vba
Rich Locus
external usenet poster
 
Posts: 8
Default Access Program Only Looping Part Way Through Outlook Inbox

One more fact. If I keep running the Access macro that runs the code listed
above, eventually all the mail gets processed. It's just a mystery why it
quits early. For example, if I have 10 emails in my Inbox, it might clear
out 6 and leave 4 in the INBOX. The next time I run it, it might process 3
of the 4 and leave 1. Then the third time I run it, it will finally clear
out the email. VERY STRANGE!!!
--
Rich Locus
Logicwurks, LLC


"Rich Locus" wrote:

Hello Outlook Group:

I am developing an Access application that reads through the Inbox (both
read and unread mail), and under certain conditions, adds the mail
information to an Access database. When I am done looking at the mail item,
I file it one one of two folders: either REJECTS or SAVED MAIL. I'm using
POP3.

The problem is that it only loops about half-way through the inbox and exits
BEFORE all the mail in the inbox folder is processed. I have two sub-folders
under the inbox, one call REJECTS and the other SAVED MAIL.

If I do a ? InboxItems.COUNT, the count of the mail is correct... i.e. it
will say I have 7 emails, and that's the correct number, but it only loops
through about 4 times instead of 7 and leaves mail in the INBOX. The code
follows. Any ideas?

Option Compare Database
Option Explicit

Public Function ReadInboxAndMoveV1()
Dim TempRst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim SavedMailFolder As Outlook.MAPIFolder
Dim RejectMailFolder As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim SavedMailItems As Outlook.MailItem
Dim RejectMailItems As Outlook.MailItem
Dim Mailobject As Object
Dim db As DAO.Database

DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from tbl_outlooktemp"
DoCmd.SetWarnings True
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox)
Set SavedMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Saved
Mail")
Set RejectMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Rejects")
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
'
Set InboxItems = Inbox.Items
'
For Each Mailobject In InboxItems
If UCase(Left(Mailobject.Subject, 6)) "CLIENT" Then
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(RejectMailFolder)
Else
With TempRst
.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(SavedMailFolder)
End With
End If
Next

Set TempRst = Nothing
Set OlApp = Nothing
Set Inbox = Nothing
Set SavedMailFolder = Nothing
Set InboxItems = Nothing
Set SavedMailItems = Nothing
Set Mailobject = Nothing

End Function

Any help would be appreciated!!!
--
Rich Locus
Logicwurks, LLC

  #3  
Old May 8th 10, 06:46 PM posted to microsoft.public.outlook.program_vba
Rich Locus
external usenet poster
 
Posts: 8
Default Access Program Only Looping Part Way Through Outlook Inbox

Moderator:
Could you please delete this post? I'm going to put in a simpler example.
--
Rich Locus
Logicwurks, LLC


"Rich Locus" wrote:

Hello Outlook Group:

I am developing an Access application that reads through the Inbox (both
read and unread mail), and under certain conditions, adds the mail
information to an Access database. When I am done looking at the mail item,
I file it one one of two folders: either REJECTS or SAVED MAIL. I'm using
POP3.

The problem is that it only loops about half-way through the inbox and exits
BEFORE all the mail in the inbox folder is processed. I have two sub-folders
under the inbox, one call REJECTS and the other SAVED MAIL.

If I do a ? InboxItems.COUNT, the count of the mail is correct... i.e. it
will say I have 7 emails, and that's the correct number, but it only loops
through about 4 times instead of 7 and leaves mail in the INBOX. The code
follows. Any ideas?

Option Compare Database
Option Explicit

Public Function ReadInboxAndMoveV1()
Dim TempRst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim SavedMailFolder As Outlook.MAPIFolder
Dim RejectMailFolder As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim SavedMailItems As Outlook.MailItem
Dim RejectMailItems As Outlook.MailItem
Dim Mailobject As Object
Dim db As DAO.Database

DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from tbl_outlooktemp"
DoCmd.SetWarnings True
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox)
Set SavedMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Saved
Mail")
Set RejectMailFolder =
OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox).Folders("Rejects")
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
'
Set InboxItems = Inbox.Items
'
For Each Mailobject In InboxItems
If UCase(Left(Mailobject.Subject, 6)) "CLIENT" Then
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(RejectMailFolder)
Else
With TempRst
.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
Set SavedMailItems = Mailobject.Move(SavedMailFolder)
End With
End If
Next

Set TempRst = Nothing
Set OlApp = Nothing
Set Inbox = Nothing
Set SavedMailFolder = Nothing
Set InboxItems = Nothing
Set SavedMailItems = Nothing
Set Mailobject = Nothing

End Function

Any help would be appreciated!!!
--
Rich Locus
Logicwurks, LLC

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Providing calendar access to someone else if not a part of a vpn Jocelyn - JYR Consulting Outlook - Calandaring 1 April 16th 10 04:12 PM
outlook doesn't want to allow another program to access it Cant do my job Outlook - Using Contacts 1 April 24th 09 11:43 PM
Looping thru Inbox RS Outlook and VBA 1 March 12th 08 06:41 AM
Not all Contacts Appear for Selection in Word Envelopes and Labe part of the program.l iceman Outlook - Using Contacts 2 July 27th 07 09:58 AM
I can't access my contacts from the export file part. How to fix? blink Outlook - Using Contacts 3 April 16th 07 01:19 AM


All times are GMT +1. The time now is 11:52 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.