I have an access 2002 database that has one table called tblInbox and one field called items.
I am trying to adapt some of this microsoft sample code to export email addresses into my tblInbox table field called items.
Here is the code so far:' Set up DAO objects (uses existing "tblInbox" table)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblInbox")
' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "MailItem" Then
Set c = objItems(i) 'THIS FAILS HERE
rst.AddNew
rst!Item = c.SenderEmailAddress
rst.Update
End If
Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No Emails to export."
End If
I commented the part that fails on a type mismatch. I just want to append all of the "SendEmailAddress" fields to my items field in my access db every time this code is run.
Can you help me?
I am trying to adapt some of this microsoft sample code to export email addresses into my tblInbox table field called items.
Here is the code so far:' Set up DAO objects (uses existing "tblInbox" table)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblInbox")
' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "MailItem" Then
Set c = objItems(i) 'THIS FAILS HERE
rst.AddNew
rst!Item = c.SenderEmailAddress
rst.Update
End If
Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No Emails to export."
End If
I commented the part that fails on a type mismatch. I just want to append all of the "SendEmailAddress" fields to my items field in my access db every time this code is run.
Can you help me?