email directly into Access Record

bkelly

Active Member
Joined
Jan 28, 2005
Messages
465
Just pondering here, but:

Is there a method to route an email directly into a record within Access?

I am thinking of an Issues monitoring system (Found a template for just this on line.) Can Outlook send the body of an email directly to Access so that it would become a record (maybe I should say tuple) within a table? I found discussions about sending emails from Access, but not about receiving into Access.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi

the easiest way is probably to link an Access table directly to Outlook.

You could then run an append query to add the 'contents' field from that table to your main table with whatever criteria you wish to apply.


atb
sumuwin
 
Upvote 0
You can harvest the emails in an Outlook folder, using the code shown below.
Each time you run it the code looks for emails dated later than the last record in your email table.
The last email is found using this query:

Code:
SELECT TOP 1 tblEmail.RecTime
FROM tblEmail
ORDER BY tblEmail.RecTime DESC;

Code:
'this routine pulls emails from Outlook to Excel and loads them into tblEmail.
'adapted for Access by Denis Wright.
'original code from VBAX, http://www.vbaexpress.com/forum/showthread.php?t=29711
'Calls: ProcessFolder

Sub Launch_Pad()
     
    Dim olApp As Outlook.Application
    Dim olNS As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim Date1, Date2
    Dim dtmLast As Date
    Dim rst As DAO.Recordset
    
    Set rst = CurrentDb.QueryDefs("qryLastMail").OpenRecordset
    If rst.BOF And rst.EOF Then 'no records
        Date1 = DateSerial(2000, 1, 1)
    Else
        dtmLast = rst!RecTime \ 1
        Date1 = DateAdd("d", 1, dtmLast)
    End If
    Date2 = DateAdd("d", 1, Date)
    
    Set olApp = Outlook.Application
    Set olNS = olApp.GetNamespace("MAPI")
    Set olFolder = olNS.PickFolder
          
    Call ProcessFolder(olFolder, Date1, Date2)
     
    rst.Close
    Set rst = Nothing
    Set olNS = Nothing
    Set olFolder = Nothing
    Set olApp = Nothing
    Set olNS = Nothing
End Sub

Sub ProcessFolder(olfdStart As Outlook.MAPIFolder, Date1, Date2)
    Dim olFolder As Outlook.MAPIFolder
    Dim olObject As Object
    Dim olMail As Outlook.MailItem
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim i As Long
     
    Set dbs = DBEngine(0)(0)
    Set rst = dbs.TableDefs("tblEmail").OpenRecordset
    i = 1
    
    For Each olObject In olfdStart.Items
        If TypeName(olObject) = "MailItem" Then
            If olObject.ReceivedTime >= Date1 And olObject.ReceivedTime < Date2 Then
                Call SysCmd(acSysCmdSetStatus, "Importing Email message " & i)
                Set olMail = olObject
                With rst
                    .AddNew
                    !Subject = olMail.Subject
                    If Not olMail.UnRead Then !ReadStatus = "Message is read" Else !ReadStatus = "Message is unread"
                    !RecTime = olMail.ReceivedTime
                    !LastMod = olMail.LastModificationTime
                    !Cat = olMail.Categories
                    !SenderName = olMail.SenderName
                    !RequestFlag = olMail.FlagRequest
                    !BodyText = olMail.Body
                    !CreateBy = Environ("username")
                    .Update
                End With
                i = i + 1
            End If
        End If
    Next
    Set olMail = Nothing
    Set olFolder = Nothing
    Set olObject = Nothing
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing
    Call SysCmd(acSysCmdClearStatus)
End Sub
Denis
 
Last edited:
Upvote 0
Here's the table structure...
<title>Excel Jeanie HTML</title> <table style="background-color: rgb(255, 255, 255); padding-left: 2pt; padding-right: 2pt; font-family: Calibri,Arial; font-size: 11pt;" border="1" cellpadding="0" cellspacing="0"><tbody> <tr style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt; font-weight: bold;"> <td> </td> <td>A</td> <td>B</td> <td>C</td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">1</td> <td>EmailID</td> <td>AutoNumber</td> <td>Primary Key</td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">2</td> <td>Subject</td> <td>Text</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">3</td> <td>ReadStatus</td> <td>Text</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">4</td> <td>RecTime</td> <td>Date/Time</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">5</td> <td>LastMod</td> <td>Date/Time</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">6</td> <td>Cat</td> <td>Text</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">7</td> <td>SenderName</td> <td>Text</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">8</td> <td>RequestFlag</td> <td>Yes/No</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">9</td> <td>BodyText</td> <td>Memo</td> <td> </td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">10</td> <td>CreateDate</td> <td>Date/Time</td> <td>Default Value = Now()</td></tr> <tr style="height: 18px;"> <td style="text-align: center; background-color: rgb(202, 202, 202); font-size: 8pt;">11</td> <td>CreateBy</td> <td>Text</td> <td> </td></tr></tbody></table>

Excel tables to the web >> Excel Jeanie HTML 4

Denis
 
Upvote 0
That is good to know. I do not know enough yet about Access to determine what it is doing, but it is interesting that you pull into Excel then into Access. Thanks for posting.
 
Upvote 0
Actually, it's direct into Access. I just used Excel to lay out the field structure, but those fields need to go into an Access table called tblEmail.

The import is quick, too. Importing around 1000 emails, then parsing the body into another table (not shown above) takes around a minute on my machine.

Denis
 
Upvote 0
Dear Denis,

While dowloading from Inbox..
we use
If olObject.ReceivedTime <= Date2 And olObject.ReceivedTime >= Date1 Then

But while downloading from Sentitem then what will we use?

If olObject.SentTime <= Date2 And olObject.SentTime >= Date1 Then ???
 
Upvote 0
That looks reasonable. Have you tried it?

I noticed in your PM that you want to attach a file. Unfortunately this board doesn't support file attachments, so you will need to post some code with a description of what you need to do.

Denis
 
Upvote 0
Hi Denis,
I have 2 sheets
Sheet1 - Have INbox Data
ColA- TO
ColB - From
ColC - Subject
ColD - Body
ColE - Received
Sheet2 - Have SentItem Data
ColA - TO
ColB - From
ColC - Subject
ColD - Body
ColE - Received
Now Sheet1 & Sheet2 both have number of rows in it as per extraction..
I need a VBA code which will help me highlight those rows which are in Sheet1 & absent in Sheet2 depending upon below 3 conditions
1) Sheet1.From = Sheet2.To
2) Sheet1.C = Sheet2.C
3) Sheet1.E <= Sheet2.E
If above condition do not match then it proves that Sheet1 & sheet2 have mismatch data, now those rows should be highlighted..
In short - This highlighted row will be the row which is in INBOX(Sheet1) & not responded so its missing in Sentitem(Sheet2)
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,398
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top