Using VB Script to Pull emails from Outlook Into MS Access Database - TechRepublic
Question
October 31, 2008 at 08:05 AM
jynessa

Using VB Script to Pull emails from Outlook Into MS Access Database

by jynessa . Updated 16 years, 11 months ago

I was wondering if anyone could take a look at my code and tell me what I am doing wrong. 🙂

A little back history on my project is that I am trying to create a database that saves information from emails into a MS Access database. I got the following code to work, but I actually need to to be pulling from a subfolder. The subfolder directory in outlook would be something like:

private folder/inbox/brand/activated

Here is the code that I am using:

Private Sub Command1_Click()
Dim TempRst As DAO.Recordset
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
Set db = CurrentDb

Set OlApp = CreateObject(“Outlook.Application”)
Set Inbox = OlApp.GetNamespace(“Mapi”).GetDefaultFolder(olFolderInbox)

Set TempRst = CurrentDb.OpenRecordset(“tbl_OutlookTemp”)

Set InboxItems = Inbox.Items

For Each Mailobject In InboxItems
If Mailobject.UnRead Then
With TempRst

.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
End With
End If
Next

Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing

End Sub

Best Regards and Many Thanks!
Jynessa Mason

This discussion is locked

All Comments