Runtime Error 438 Object doesn't support this property or object

Posted on 2006-04-15
Last Modified: 2008-01-09
I am using the following code:
Private Sub btnNewMail_Click()
    Dim colItems        As Outlook.Items
    Dim objCurrentItem  As Object
    Dim strSQL          As String
    Dim dbs             As Database
    Dim tdf             As TableDef
    Dim rst             As DAO.Recordset
    Dim intDuplicates   As Integer
    Dim intI            As Integer
    Dim Attachment9     As String
    Dim dummy As String
On Error GoTo Error_btnNewMail_Click
    Set colItems = GetMailboxNetworkInput(Me.cmbMap, Me.cmbFolder)
    If colItems Is Nothing Then
        MsgBox "No items found"
        ' Return Database object variable pointing to current database.
        Set dbs = CurrentDb
        ' Return TableDef object variable pointing to Mail table.
        Set rst = dbs.OpenRecordset("Mail")
        ' Add to table Mail
        'DoCmd.Hourglass True
        DoCmd.SetWarnings False
        For Each objCurrentItem In colItems
            If Not fncMailExist(objCurrentItem.EntryID) Then
                rst!EntryID = objCurrentItem.EntryID
                rst!ReceivedTime = objCurrentItem.ReceivedTime
                rst!Subject = objCurrentItem.Subject
                rst!SenderName = objCurrentItem.SenderName
                rst!CC = objCurrentItem.CC
                rst!Body = fncReplaceTabs(objCurrentItem.Body)
                rst!Attachments = objCurrentItem.Attachments.Count
                'Save attachments in c:\temp
                Attachment9 = ""
                If objCurrentItem.Attachments.Count > 0 Then
                    For intI = 1 To objCurrentItem.Attachments.Count
                        objCurrentItem.Attachments.Item(intI).SaveAsFile ("T:\Cost Mailbox\Mail Attachments\" & objCurrentItem.Attachments.Item(intI))
                        Attachment9 = Attachment9 & "," & objCurrentItem.Attachments.Item(intI)
                    Next intI
                End If
                rst!AttachmentsName = Mid(Attachment9, 2)
                intDuplicates = intDuplicates + 1
                If intDuplicates = 1 Then MsgBox "Duplicate emails were found.  These items will not be imported into the log."
            End If
        Next objCurrentItem
        DoCmd.SetWarnings True
        'DoCmd.Hourglass False
        Set rst = Nothing
        Set dbs = Nothing
    End If
    GoTo Exit_btnNewMail_Click

Select Case Err
    Case 3022, 6
        Resume Next
    Case Else
        MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
End Select

MsgBox "Emails have been logged into the Database.", vbOKOnly, "Get Emails"

End Sub

When I click on the button that runs this, I get "Error 438 Object doesn't support this property or object".  Can someone tell me why this is happening and how to fix it?
Question by:cobianna
    LVL 44

    Expert Comment

    by:Leigh Purvis
    You really need to (temporarily) remove your error handling to determine where the error is occuring.
    Just comment out the line
    'On Error GoTo Error_btnNewMail_Click

    It could be occuring in your called procedures
    GetMailboxNetworkInput, fncMailExist or fncReplaceTabs

    Author Comment

    The error occured at the following line:
         rst!ReceivedTime = objCurrentItem.ReceivedTime

    Any suggestions?
    LVL 44

    Expert Comment

    by:Leigh Purvis
    So I presume that GetMailboxNetworkInput returns the collection of mails from a specific folder in Outlook?
    What is the code in GetMailboxNetworkInput ?

    Is there a particular reason that you declare
    Dim objCurrentItem  As Object
    instead of
    Dim objCurrentItem  As Outlook.MailItem

    Does the collection not iterate if you do that?

    Author Comment

    Here is the code for "GetMailboxNetworkInput":
    Function GetMailboxNetworkInput(strMapNameLike As String, strFolderName As String) As Outlook.Items
        ' This procedure returns the items of the Outlook mailbox folder.                            *
        ' That is identified by:                                                                     *
        ' strMapNameLike = unique "Instr" part of MAP from outlook                                   *
        ' strFoldername  = name of folder                                                            *
        ' These variables have been specified to be able to identify the "Input" folder of the       *
        ' correct mailbox                                                                            *
        ' For the use within this application normally "Network" and "Input" will be specified       *
        Dim colMaps     As Outlook.Folders
        Dim colFolders  As Outlook.Folders
        Dim fldFolder   As Outlook.MAPIFolder
        Dim fldMap      As Outlook.MAPIFolder
        ' Use the InitializeOutlook procedure to initialize global
        ' Application and NameSpace object variables, if necessary.
        If golApp Is Nothing Then
            If InitializeOutlook = False Then
                MsgBox "Unable to initialize Outlook Application " _
                    & "or NameSpace object variables!"
                Exit Function
            End If
        End If
        Set colMaps = gnspNameSpace.Folders
        For Each fldMap In colMaps
            If InStr(fldMap.Name, strMapNameLike) > 0 Then
                Set colFolders = fldMap.Folders
                For Each fldFolder In colFolders
                    If fldFolder.Name = strFolderName Then
                        Set GetMailboxNetworkInput = fldFolder.Items
                        Exit Function
                    End If
                Next fldFolder
            Set GetMailboxNetworkInput = Nothing
            End If
        Next fldMap
    End Function

    I did not create this code so I'm not sure why they would have used As Object instead of As Outlook.MailItem.
    LVL 44

    Accepted Solution

    Try switching the declaration for now - see if it highlights the problem any earlier (when you compile or first run it).

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now