Importing Emails from an Exchange Email box

G

GLT

Hi,

I am currently (manually) importing emails into my DB.

I am only importing the following fields from each mail item:

1) Receive Date
2) From
3) Subject
4) Body

I would like to automate this process with code - so that the user click a
button and the fields above are imported into a table called 'Daily Results',
with field names the same as 1,2,3 and 4 above.

Can anyone advise of how to do this? I thought MS Access had an 'Import
Builder' where these setting could be saved, and recalled when required (like
a Macro) but I cannot seem to find this.

Any help would be greatly appreciated.

Cheers,
GLT.
 
G

GLT

Hi,

After some searching high and low I cam up with the following code which
copies all emails from an Outlook folder called "ResultsFolder" to an Access
Table called "ResultsTable".

The following feilds cre copied from each email:

Received
From
Subject
Body


Sub ImportEmailsFromOutlook()

' This code is based in Microsoft Access.


Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("ResultsTable")

' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim objFolder As Outlook.MAPIFolder

' Set up varibles
Dim iNumEmails As Variant
Dim i As Variant
Dim FolderName As Variant



FolderName = "ResultsFolder"
Set olns = ol.GetNamespace("MAPI")
Set objFolder = olns.GetDefaultFolder(olFolderInbox).Folders(FolderName)
Set objItems = objFolder.Items


Forms![frm_MainMenu]![Status] = "Importing Message Email Messages"

iNumEmails = objItems.Count
If iNumEmails > 0 Then
For i = 1 To iNumEmails
Set c = objItems(i)
testDate = c.ReceivedTime
todayDate = Date


Forms![frm_MainMenu]![Status] = "Importing Message: " &
c.Subject

rst.AddNew
rst!Received = c.ReceivedTime
rst!From = c.SenderEmailAddress
rst!Subject = c.Subject
rst!Body = c.Body
rst.Update


Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No emails to export."
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top