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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-Time Error 438 (Access - Outlook)

Status
Not open for further replies.

eilob

Programmer
Mar 28, 2007
54
IE
Hi all,
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

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
 
First, olMail is a Constant ! (use objMail instead)
Similar for all your OlXXX objects !!!
...
For Each objMail In objItems
If TypeOf objMail Is MailItem Then
If objMail.UnRead = True Then
...
End If
End If
Next objMail

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for that, i think is working better.
It is copying must of the emails with exception of one type of emails that are Generated emails.
Am i missing some type of variables or declarations to accept this type of emails??





 
Sorry just to make it more clear, the emails that cant be moved are receipts when people Read them, and other ones are other type of receipts which say Message Recall Success, or other times, Message Recall Failure.

Thannksss! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top