Import Email to Access Table

TallMan

Registered User.
Local time
Today, 17:04
Joined
Dec 5, 2008
Messages
239
Good Afternoon All,

I have thankfully aquired the code below from this website http://blogs.techrepublic.com.com/howdoi/?p=119. The code allows me to run this macro in outlook and insert all of the emails in a folder I select into an access table.

When the macro runs the outlook folder list populates and allows you to select a folder. Once you select the folder and hit ok all of the emails are inserted into my "email" table in my Access database.

Can anyone get me on the right path so that I can go one step further and select individual emails and send them to the "email" table?

Looking at the code if I did one email, I would not need the loop. I am thinking I just need to make a few changes to make it a single email option.
But have no idea where to start!

PHP:
Sub ExportMailByFolder()  'Export specified fields from each mail  'item in selected folder.  Dim ns As Outlook.NameSpace  Dim objFolder As Outlook.MAPIFolder ' I think this needs to be changed  Set ns = GetNamespace("MAPI")  Set objFolder = ns.PickFolder ' I think this needs to be changed  Dim adoConn As ADODB.Connection  Dim adoRS As ADODB.Recordset  Dim intCounter As Integer  Set adoConn = CreateObject("ADODB.Connection")  Set adoRS = CreateObject("ADODB.Recordset")  'DSN and target file must exist.  adoConn.Open "DSN=OutlookData;"  adoRS.Open "SELECT * FROM email", adoConn, _       adOpenDynamic, adLockOptimistic  'Cycle through selected folder.  For intCounter = objFolder.Items.Count To 1 Step -1   With objFolder.Items(intCounter)   'Copy property value to corresponding fields   'in target file.    If .Class = olMail Then      adoRS.AddNew      adoRS("Subject") = .Subject      adoRS("Body") = .Body      adoRS("FromName") = .SenderName      adoRS("ToName") = .To      adoRS("FromAddress") = .SenderEmailAddress      adoRS("FromType") = .SenderEmailType      adoRS("CCName") = .CC      adoRS("BCCName") = .BCC      adoRS("Importance") = .Importance      adoRS("Sensitivity") = .Sensitivity      adoRS.Update     End If    End With   Next  adoRS.Close  Set adoRS = Nothing  Set adoConn = Nothing  Set ns = Nothing  Set objFolder = NothingEnd Sub

Thank you for your time!!:(
 

Users who are viewing this thread

Back
Top Bottom