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

Question about CDO 1.21



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 7th 09, 06:00 PM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Question about CDO 1.21

I have a real simple function that all it does is Delete messages older than
X days. I'm not sure why, but if I run it once it deletes some of the
messages but not all. With 1000's of messages in the folder it may take 3 or
4 runs for it to finally delete all the messages over X days. Is there some
problem with CDO where it can only process a small number of messages at one
time?

Dim NumDaysToDelete

NumDaysToDelete = 3

CleanMail(NumDaysToDelete)

Sub CleanMail
Dim oSession
Set oSession = CreateObject("MAPI.Session")

strProfileInfo = "cgyex001" & vblf & "ecntrckm"

oSession.Logon "", "", False, True, 0, True, strProfileInfo

Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim oMessages
Set oMessages = oFolder.Messages
For Each oMessage In oMessages
If DateDiff("d",oMessage.TimeReceived,now) = NumDaysToDelete Then
oMessage.Delete
End if
Next
End Sub
Ads
  #2  
Old January 7th 09, 06:52 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Question about CDO 1.21

This has nothing to do with CDO and everything to do with using a For...Each
loop. That and a count up For loop establish an index counter into the
collection of items and every time you delete an item it messes with the
index. Usually that results in deleting 1/2 of the items within the loop.

Use a count down For loop (Step -1) or a Do loop that checks for count of
items instead and it should work as expected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Bob Smith" wrote in message
...
I have a real simple function that all it does is Delete messages older
than
X days. I'm not sure why, but if I run it once it deletes some of the
messages but not all. With 1000's of messages in the folder it may take 3
or
4 runs for it to finally delete all the messages over X days. Is there
some
problem with CDO where it can only process a small number of messages at
one
time?

Dim NumDaysToDelete

NumDaysToDelete = 3

CleanMail(NumDaysToDelete)

Sub CleanMail
Dim oSession
Set oSession = CreateObject("MAPI.Session")

strProfileInfo = "cgyex001" & vblf & "ecntrckm"

oSession.Logon "", "", False, True, 0, True, strProfileInfo

Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim oMessages
Set oMessages = oFolder.Messages
For Each oMessage In oMessages
If DateDiff("d",oMessage.TimeReceived,now) = NumDaysToDelete Then
oMessage.Delete
End if
Next
End Sub


  #3  
Old January 7th 09, 07:28 PM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Question about CDO 1.21

Thanks for your help. I guess I'm still having trouble trying to get this to
work. I don't know the number of items to be deleted until I have evaluated
the Receieved time. I tried a Do While Not oMessage Is Nothing Loop, but
still run into the same problem. I also checked the CDOLive website, but I am
still having problems coming to terms with the concept. Any chance you can
guide me as to what I am doing wrong.

"Ken Slovak - [MVP - Outlook]" wrote:

This has nothing to do with CDO and everything to do with using a For...Each
loop. That and a count up For loop establish an index counter into the
collection of items and every time you delete an item it messes with the
index. Usually that results in deleting 1/2 of the items within the loop.

Use a count down For loop (Step -1) or a Do loop that checks for count of
items instead and it should work as expected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Bob Smith" wrote in message
...
I have a real simple function that all it does is Delete messages older
than
X days. I'm not sure why, but if I run it once it deletes some of the
messages but not all. With 1000's of messages in the folder it may take 3
or
4 runs for it to finally delete all the messages over X days. Is there
some
problem with CDO where it can only process a small number of messages at
one
time?

Dim NumDaysToDelete

NumDaysToDelete = 3

CleanMail(NumDaysToDelete)

Sub CleanMail
Dim oSession
Set oSession = CreateObject("MAPI.Session")

strProfileInfo = "cgyex001" & vblf & "ecntrckm"

oSession.Logon "", "", False, True, 0, True, strProfileInfo

Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim oMessages
Set oMessages = oFolder.Messages
For Each oMessage In oMessages
If DateDiff("d",oMessage.TimeReceived,now) = NumDaysToDelete Then
oMessage.Delete
End if
Next
End Sub



  #4  
Old January 7th 09, 08:50 PM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Question about CDO 1.21

Got it working, thanks for your help.


"Ken Slovak - [MVP - Outlook]" wrote:

This has nothing to do with CDO and everything to do with using a For...Each
loop. That and a count up For loop establish an index counter into the
collection of items and every time you delete an item it messes with the
index. Usually that results in deleting 1/2 of the items within the loop.

Use a count down For loop (Step -1) or a Do loop that checks for count of
items instead and it should work as expected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Bob Smith" wrote in message
...
I have a real simple function that all it does is Delete messages older
than
X days. I'm not sure why, but if I run it once it deletes some of the
messages but not all. With 1000's of messages in the folder it may take 3
or
4 runs for it to finally delete all the messages over X days. Is there
some
problem with CDO where it can only process a small number of messages at
one
time?

Dim NumDaysToDelete

NumDaysToDelete = 3

CleanMail(NumDaysToDelete)

Sub CleanMail
Dim oSession
Set oSession = CreateObject("MAPI.Session")

strProfileInfo = "cgyex001" & vblf & "ecntrckm"

oSession.Logon "", "", False, True, 0, True, strProfileInfo

Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim oMessages
Set oMessages = oFolder.Messages
For Each oMessage In oMessages
If DateDiff("d",oMessage.TimeReceived,now) = NumDaysToDelete Then
oMessage.Delete
End if
Next
End Sub



 




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
BCC Question CWLee Outlook Express 3 November 12th 07 09:49 PM
Question on CIW Abhi Outlook - Installation 0 August 12th 07 07:46 PM
set-up question Savvy3 Outlook - General Queries 3 February 23rd 07 08:21 PM
question Steve Baker Outlook - Using Forms 1 September 5th 06 09:31 PM
Another Question. Bewildered Outlook - Using Contacts 3 August 22nd 06 02:51 AM


All times are GMT +1. The time now is 09:52 PM.


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