PDA

View Full Version : run-time 438: object doesn't support this property or method



Graham_T
10-18-2013, 12:44 AM
Hi all,

I have inherited some automated processes that read and parse incoming emails (Outlook 2007) before extracting data and sending to an Access database.

Most of the time this runs without any error, however occasionally the code will break with a run-time 438: object doesn't support this property or method

The line it breaks on is:


sPerson = mailItem.SenderName

The code prior to this is:


Option Explicit
Private ns As Outlook.NameSpace
Private sEmailAddress As String
Private sPerson As String
Private dReceived As Date
Private sComments As String
Private sSerialNo As String
Private sCLMtrFrm As String
Private sItemNo As String
Private oConnection As Object
Private sItem As String
Private M1 As String
Private M2 As String
Private M3 As String
Private M4 As String
Private M5 As String
Private M6 As String
Sub ReadE3(ByVal mailItem As Object)
Dim lCount As Long
Dim sql As String
Dim sDate As String
Dim sqlM As String
Dim sqlR As String
Dim sSerialDummy As String
Dim sCLMtrFrmDummy As String
Dim sDiv As String
'// Collect team division for use in Stats reporting and append to audit table.
If InStr(1, mailItem.Subject, "Our Ref: E3 [EIE]") Or InStr(1, mailItem.Subject, "ref E3 [EIE]") Then
sDiv = "EIE"
End If
If InStr(1, mailItem.Subject, "Our Ref: E3 [NRW]") Or InStr(1, mailItem.Subject, "ref E3 [NRW]") Then
sDiv = "NRW"
End If
If InStr(1, mailItem.Subject, "Our Ref: E3 [SSC]") Or InStr(1, mailItem.Subject, "ref E3 [SSC]") Then
sDiv = "SSC"
End If

'// Used when entering dummy values into E3Audit table when email cannot be read
sSerialDummy = "ABC123"
sCLMtrFrmDummy = "XYZ123"

Call openConnection

sPerson = mailItem.SenderName
sEmailAddress = mailItem.SenderEmailAddress
dReceived = mailItem.ReceivedTime


I'm not really used to coding in Outlook, so unsure as to how to handle this error.

Thanks in advance for any advice you can offer

GT

Aflatoon
10-18-2013, 12:54 AM
I imagine the problem is that whatever object is being passed as the Mailitem variable is not, in fact, a MailItem object and therefore doesn't have a sendername. What does the calling code look like?

mrojas
10-19-2013, 01:28 PM
Do you know when, under what specific conditions, the code will break? Have you step-debugged code?