PDA

View Full Version : SenderName property failing inexplicably.



Helix
04-04-2008, 09:39 AM
I'm using a for each next loop through a large list of emails in a folder--about 2500 emails. I am setting a variable equal to <expression>.SenderName of each item (each mail item) so that I can perform some comparisons--I'm deleting duplicate emails based upon several criteria, including subject lines that are identical.

The vba code I have written works 99% of the time, but once every several hundred or so emails--sometimes almost a thousand--it creates a runtime error: "Object doesn't support this property or method" with a run time error # of 438. I have looked at the emails that cause the error and I cannot discern any special qualities in them. They all have display names, which I thought was equivalent to the Sendername property. Of late it seems to come from mass emails, or notifications of message delivery failure, or emails coming from senders such as info@ a domain name, or autoreply emails used by persons on vacation.

But sometimes it also occurs with emails from individuals, although less so. Does anyone have a clue what I am encountering?

This is running on Outlook 2002 SP3 so I do not have access to the actual sender email. This is because of the limitation of the outlook object model in the 2002 version that was "corrected" or expanded upon in later versions to provide such access.

The loop is as follows:
For Each objItem In objItems
where I have previously declared Dim objItems As Items
and Dim objItem As Object.

I also run a series of checks as follows before attempting to access the SenderName property:
If objItem.Class = olMail Then SubjectLine = objItem.Subject

I run other tests as well to exclude from consideration subject lines that would cause problems--and that I will tackle some other day--such as subject lines containing single quotes, and subject lines that are of zero length (blank subject lines).

I also created an error handler for the SenderName error but it appears to work sometimes or only once and from then on my vba code craps out. The error handler is as follows:
On Error GoTo SenderNameErrorHandler
Sender = objItem.SenderName
On Error GoTo 0 'turn off special error handler
... other code ...
Exit Sub
SenderNameErrorHandler:
'if this error occurs assume that email would be deleted in error if we 'ignored the error therefore skip the email and go to the next one
StringArray(a, 0) = SubjectLine
a = a + 1
GoTo Line1
End Sub

Line 1 is the Next in the For Each Next Loop, and the array was created to help me figure out which emails are causing errors--I would run the code with a breakpoint just before terminating so I could examine the contents of the array. I've never even managed to get the code to execute that far cleanly because I keep getting the SenderName error described above. And for some reason, after a few times of getting the error, the error handler appears to fail. The line executes, but fails to jump to the error handler.

I manually--using the debugger--set the sendername to some nonsense string to see how much further it will run, but invariably it isn't very far and I cannot make sense of the error. The first of the errors now show up between the 800th and 900th email examined.

Thank you all.