I am trying to move emails from Outlook into an Access table, the code below worked for me before, but now I am having a problem as this error message comes up: Run-time error 438 'Object doesn't support this property or method', for some emails is ok, but otherones, it just cant find the data of certain fields such as Received Time, From etc
Please if someone could help me with some advice.. Thankss
Expand|Select|Wrap|Line Numbers
- Private Sub Command0_Click()
- Dim Olapp As Outlook.Application
- Dim Olmapi As Outlook.NameSpace
- Dim Olfolder As Outlook.MAPIFolder
- Dim OlMail As Object
- Dim OlMessage As Outlook.MailItem
- Dim OlItems As Outlook.Items
- Dim OlRecips As Outlook.Recipients
- Dim OlRecip As Outlook.Recipient
- Dim db As DAO.Database, rst As DAO.Recordset
- Dim flgSave As Boolean
- Dim DQ As String
- 'Dim SubFolder As MAPIFolder
- Set db = CurrentDb
- Set rst = db.OpenRecordset("tbl_Mail", dbOpenDynaset) 'Open table tblMail
- 'Create a connection to outlook
- Set Olapp = CreateObject("Outlook.Application")
- Set Olmapi = Olapp.GetNamespace("MAPI")
- 'Open the PSC-EMEA inbox
- Set Olfolder = Olmapi.GetDefaultFolder(olFolderInbox).Folders.Item("Mail Read")
- Set OlItems = Olfolder.Items
- For Each OlMail In OlItems
- If OlMail.UnRead = True Then
- rst.AddNew
- rst!Date = OlMail.ReceivedTime
- rst!Time = OlMail.ReceivedTime
- rst!From = OlMail.SenderName
- rst!Subject = OlMail.Subject
- rst!Body = OlMail.Body
- rst!CreationTime = OlMail.CreationTime
- rst!LastModificationTime = OlMail.LastModificationTime
- rst!Last_Checked = Now
- rst.Update
- OlMail.Delete
- End If
- Next OlMail
- MsgBox "New mails have been updated. Please check the tbl_Mail details", vbOKOnly
- 'Release memory
- Set Olapp = Nothing
- Set Olmapi = Nothing
- Set Olfolder = Nothing
- Set OlItems = Nothing
- Set OlMail = Nothing
- Set OlMessage = Nothing
- Set rst = Nothing
- Set db = Nothing
- End Sub