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

Retrieve Information from Outlook

maxamis4
Expert 100+
P: 295
Hello,

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
To
and
From
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
  10.  
  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
  16.  
  17. Set olns = GetNamespace("MAPI")
  18.  
  19. Set cf = olns.GetDefaultFolder(olFolderInbox)
  20.  Debug.Print cf
  21.  
  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
  28.  
  29.    Debug.Print Item.Subject ' here is where I want to retrieve the fields
  30.     '.Subject
  31.     '.body
  32.     Next Item
  33. End Sub
  34.  
  35.  
Thanks for any help
Jan 2 '07 #1
Share this Question
Share on Google+
7 Replies


100+
P: 153
I don't get what the question is...is 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

maxamis4
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

100+
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:
http://www.thescripts.com/forum/show...47#post2286847

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

NeoPa
Expert Mod 15k+
P: 31,186
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

NeoPa
Expert Mod 15k+
P: 31,186
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

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

NeoPa
Expert Mod 15k+
P: 31,186
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.