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!

Tweak MAPI Export code

Status
Not open for further replies.

jacob94

Technical User
Dec 5, 2005
161
US
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?
 
some discrepancy:
Dim c As Outlook.[!]ContactItem[/!]
...
If TypeName(objItems(i)) = "[!]MailItem[/!]" Then
Set c = objItems(i) 'THIS FAILS HERE

You may try this:
Dim c As Outlook.MailItem

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Now it errors on
rst!Item = c.SenderEmailAddress

Object does not support this object or method
 
the senderEmailAddress field is not a choice in the VBA drop down. I think it is hidden because of security? How can I get access to it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top