[dba-Tech] Cycling through Outlook Items using VBA

MartyConnelly martyconnelly at shaw.ca
Fri Jul 13 21:48:23 CDT 2007


You could try this Link Outlook contacts to an Access database
a folder might work.
http://office.microsoft.com/en-ca/help/HA011165811033.aspx
or

Here is a sample of code. You'll need
to modify it to accomplish what you want exactly.
'From:         "siebeneck yon (slc1yps)" <slc1yps at UPS.COM>
Public Function ReadMail()

  Dim OL As Outlook.Application
  Dim nsOL As Outlook.NameSpace
  Dim fldFolder As Outlook.MAPIFolder
  Dim DB As DAO.Database
  Dim RS As DAO.Recordset
  Dim olMailList As Object
  Dim olMailLists As Object

  Set DB = CurrentDb()
  Set RS = DB.OpenRecordset("tbAccessL")
  Set OL = New Outlook.Application
  Set nsOL = OL.GetNamespace("MAPI")
  Set fldFolder = nsOL.Folders("Personal
Folders").Folders("Inbox").Folders("Access-L")

  Set olMailLists = fldFolder.Items

    For Each olMailList In olMailLists

      With RS
        .AddNew
        !MsgSender = olMailList.SenderName
        !MsgSubject = olMailList.Subject
        !MsgSent = olMailList.ReceivedTime
        .Update
      End With

    Next olMailList

  Set fldFolder = Nothing
  Set nsOL = Nothing
  Set OL = Nothing

  RS.Close
  Set RS = Nothing
  DB.Close
  Set DB = Nothing

End Function



Susan Harkins wrote:

>I asked this over on Access-d, but didn't see a response. Sorry for those of
>you that are seeing a repeat. 
>
>I'm trying to export mail items to an Access data. A wizard takes care of
>this nicely, if you go the manual route. The wizard will create a database
>if it doesn't exist and will export all the fields without specifically
>mapping them to an Access table -- it works great. 
>
>Using VBA, the only way I've found to do the same is to cycle through all
>the mail fields and using a Recordset object add them to an existing
>database with the appropriate table fields. 
>
>Now, I expected to find some easy-to-implement export method in the form,
>but I haven't. My code lets the user select a folder and checks for the
>folder "type" using a For loop that counts items in the folder: 
>
>For I = CurrentFolder.Items.Count To 1 Step -1
>
>but then I have to hardcode all the mail fields -- was hoping to avoid all
>that. 
>
>Is there an export function? I can't find it in Outlook's VBA Help. Also, I
>really thought a For Each would be better, but can't get the objects right.
>
>Susan H. 
>
>_______________________________________________
>dba-Tech mailing list
>dba-Tech at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-tech
>Website: http://www.databaseadvisors.com
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the dba-Tech mailing list