Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Sent Items Mail SentOn Property

Status
Not open for further replies.

bodmin

Technical User
Apr 1, 2004
98
GB
Hi guys,

I am trying to write a bit of code that will loop through my sent items folder and pick out the task status messages that my system is sending.

Within these messages I then want to check whether they have been sent over 14 days previously, if this is the case I would then like the code to delete these task updates.

At present my code is as follows:

Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)

iCount = myFolder.Items.Count

For i = 1 To iCount
Set myMail = myFolder.Items(i)
If (Left(myMail.Subject, 11) = "Task Update") Or (Left(myMail.Subject, 14) = "Task Completed") Or (Left(myMail.Subject, 13) = "Task Accepted") Then
DateSinceCompletion = DateDiff("d", myMail.SentOn, Date, vbMonday)
If DateSinceCompletion > 14 Then
myMail.Delete
iCount = iCount - 1
End If
End If
Next

Set myolapp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing

When I run this code it is reporting an object does not support this property or method error. Has anybody got any ideas on what I am doing wrong here?

any help greatly appreciated
Andi
 
On what line does the err occur?

the line
Code:
If (Left(myMail.Subject, 11) = "Task Update") Or (Left(myMail.Subject, 14) = "Task Completed") Or (Left(myMail.Subject, 13) = "Task Accepted") Then

looks strange. I would have written:
Code:
If Left(myMail.Subject, 11) = "Task Update" Or Left(myMail.Subject, 14) = "Task Completed" Or Left(myMail.Subject, 13) = "Task Accepted" Then

Everybody body is somebodys Nutter.
 
Hi

It is failing on the line containing DateSinceCompletion = DateDiff("d", myMail.SentOn, Date, vbMonday)
with an error message of 'Object doesn't support this property or method'

As a side point I have edited my conditional test on the mail subject to as you suggested above and I still have the same error.

many thanks for help, any further ideas
 
Where is DateSinceCompletion defined? what type is this var?

Everybody body is somebodys Nutter.
 
Chris,

I have not got DateSinceCompletion defined at present and therefore this should be interpreted as a Variant datatype.

Will try declaring this variable and see if it helps

cheers
 
I have now declared the DateSinceCompletion as a an integer variable and code has changed to the following:

Dim myolapp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myFolder As MAPIFolder
Dim DateSinceCompletion As Integer


Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)

iCount = myFolder.Items.Count
If iCount > 0 Then
DateSinceCompletion = 0
For i = 1 To iCount
DateSinceCompletion = 0
Set myMail = myFolder.Items(i)
If Left(myMail.Subject, 11) = "Task Update" Or Left(myMail.Subject, 14) = "Task Completed" Or Left(myMail.Subject, 13) = "Task Accepted" Then
myMail.Display
SentDate = myMail.SentOn
MsgBox ("Sent On : " & SentDate)
DateSinceCompletion = DateDiff("d", SentDate, Date, vbMonday)
If DateSinceCompletion > 14 Then
myMail.Delete
iCount = iCount - 1
End If
End If
Next

'myFolder.Display
MsgBox ("Number of sent mails : " & myFolder.Items.Count)
End If

The code now fails on the line where I am trying to assign the myMail.SentOn to a variable called SentDate, with an error message of Object doesn't support this property or method.

Any ideas greatly appreciated
 
Sorry for the delay in my responce, I've been away from the desk.

Is SentDate defined as a Date or String?
I'd firstly investigate the type returned from MyItem.SentOn, maybe put it into a string var then convert it to a date.

Everybody body is somebodys Nutter.
 
Have found the problem. The item being returned was resolving as a taskrequestupdateitem rather than mail item. This meant I needed to use the created on date rather than the sent on date.

many thanks for your help in correcting this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top