By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

Retrieve Information from Outlook

Expert 100+
P: 295

I am currious to know how I can extract information from outlook into access. So far I have this code which I am using to test, but I can' t find any other information on the net. All I want to extract is the
fields from outlook. Below is my code

Expand|Select|Wrap|Line Numbers
  1. Public Sub Message()
  2.     Dim rst As DAO.Recordset
  3.    '## Declare Outlook objects.
  4.     Dim ol As New Outlook.Application
  5.     Dim olns As Outlook.NameSpace
  6.     Dim cf As Outlook.MAPIFolder ' Items in Inbox
  7.     Dim objItems As Outlook.Items
  8.     Dim Prop As Outlook.UserProperty
  9.    '## End Declare Outlook
  11.  Dim objOutlookMsg As Object
  12.  Dim Item As Object
  13.  Dim Atmt As Attachment
  14.  Dim FileName As String
  15.  Dim i As Integer
  17. Set olns = GetNamespace("MAPI")
  19. Set cf = olns.GetDefaultFolder(olFolderInbox)
  20.  Debug.Print cf
  22.  i = 0
  23.  If cf.Items.Count = 0 Then
  24.     MsgBox "there are no messages in that box"
  25.     Exit Sub
  26.  End If
  27.     For Each Item In cf.Items
  29.    Debug.Print Item.Subject ' here is where I want to retrieve the fields
  30.     '.Subject
  31.     '.body
  32.     Next Item
  33. End Sub
Thanks for any help
Jan 2 '07 #1
Share this Question
Share on Google+
7 Replies

P: 153
I don't get what the question the for each not working properly with outlook? If not you could try a loop and a with until IsEmpty(Items) or something like that? I'm not completely familiar with how outlook works with access...but I'm currently trying to do something with it myself and somewhat miserably failing so take my advice for what it's worth lol.

also maybe there's some sort of read command you need to do first? I'll let you know if I come across anything more useful.
Jan 2 '07 #2

Expert 100+
P: 295
Now the code works fine, my problem is that I don't know all the outlook constants. like body = message, subject = subject. I want to know how to mine/retrieve the to and from field from outlook.

What exactly are you working on, maybe I can help you with that?

Thanks for the reply
Jan 2 '07 #3

P: 153
oh great...yeah I thought I had seen that get command so I wasn't sure why it wasn't working properly. I'm trying to add multiple attachments to access...but they aren't simple file locations....the code is here:

I'm not even sure it's something I can do. I've been searching all day and I haven't even seen a website that's touched on this subject...including an online university type of thing this company has....but any help would be very appreciated...thanks :)
Jan 2 '07 #4

Expert Mod 15k+
P: 31,494
If the Item referred to is an Outlook.MailItem item, then To is a string property but From doesn't exist. SenderName is also a string which might return what you're after.
Jan 3 '07 #5

Expert Mod 15k+
P: 31,494
To find out these details go to the VBA window in Outlook and press F2 (Object Browser).
In the DropDown which says All Libraries, select Outlook.
Find MAPIFolder in the classes list, then see Items as a Member (property).
From here I guessed that this was a collection property containing Mails and/or Contacts and/or Notes etc.
I found a class MailItem so looked in the Members list for To - found and From - not found.
I looked around further and found SenderName.
There are other members and methods of this class listed.
Jan 3 '07 #6

Expert 100+
P: 295
Excellent suggestion. Wow I have more than a handful thank you so much
Jan 3 '07 #7

Expert Mod 15k+
P: 31,494
No problem.
Glad to help.
Jan 3 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.