Microsoft Access
--
Questions
--
Followers
Top Experts
Parsing Email Body to Microsoft Access
I Â would like some help with creating a way for Outlook to check for subject "Move in a Resident" Â coming into a particular email address, then parsing the email body data and populating into an access database table. Below is how the body of the email is formatted.
The subject will always be "Move in a Resident"
Applicant Details:
-- Doe, John D Â SSN: 000000000
Rent Amount: $700.00
Move In Date: 08/03/2013
Address: 3701 Cimarron Blvd Corpus, Christi, TX 78414
The fields in Microsoft Access Database "Move In" Table "Move In"are
Name
SSN
MoveInAddress
Rent
MoveInDate
All help will be appreciated. I am using Access and Outlook 2013
The subject will always be "Move in a Resident"
Applicant Details:
-- Doe, John D Â SSN: 000000000
Rent Amount: $700.00
Move In Date: 08/03/2013
Address: 3701 Cimarron Blvd Corpus, Christi, TX 78414
The fields in Microsoft Access Database "Move In" Table "Move In"are
Name
SSN
MoveInAddress
Rent
MoveInDate
All help will be appreciated. I am using Access and Outlook 2013
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
This is an exact  duplicate of this: https://www.experts-exchange.com/questions/28221319/How-to-parse-email-body-to-Microsoft-Access.html
Not quite but close now I am using outlook and access 2013 and I reworded a little.
Here is my code so far I have it going to Excel for right now just for testing purposes. I have copied this code from someone else. Â My problem. is that the name and SSN are going into the same field "SSN" and address isn't parsing at all. Â Rent amount and move in date are working correctly. Â Please help I am VBA impaired especially when it comes to outlook.
Here is my code so far I have it going to Excel for right now just for testing purposes. I have copied this code from someone else. Â My problem. is that the name and SSN are going into the same field "SSN" and address isn't parsing at all. Â Rent amount and move in date are working correctly. Â Please help I am VBA impaired especially when it comes to outlook.
Sub CaptureData(MyMail As MailItem)
Dim SenderName As String, SentTime As String, MailBody As String, strFileName As String
Dim MyArray() As String, SSN As String, RentAmount As String
Dim strTemp() As String, MoveInDate As String, Address As String
Dim LastRow As Long
Dim oXLApp As Excel.Application
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
On Error GoTo Whoa
'~~> Change File Applicant Details Here
strFileName = "C:\Users\CFO.NVART\Documents\Data1.xls"
'~~> Extraction of Details
strID = MyMail.EntryID
MailBody = MyMail.Body
MyArray = Split(MailBody, vbNewLine)
For i = LBound(MyArray) To UBound(MyArray)
'Applicant Details:
If InStr(1, MyArray(i), "Applicant Details:", vbTextCompare) Then
strTemp = Split(MyArray(i), "Applicant Details:")
SenderName = Trim(strTemp(1))
End If
'SSN
If InStr(1, MyArray(i), "SSN:", vbTextCompare) Then
strTemp = Split(MyArray(i), "SSN:")
SSN = Trim(Replace(MyArray(i), "SSN:", ""))
End If
'Rent Amount
If InStr(1, MyArray(i), "Rent Amount:", vbTextCompare) Then
strTemp = Split(MyArray(i), "Rent Amount:")
RentAmount = Trim(Replace(MyArray(i), "Rent Amount:", ""))
End If
'Move in Date:
If InStr(1, MyArray(i), "Move in Date:", vbTextCompare) Then
strTemp = Split(MyArray(i), "Move in Date:")
MoveInDate = Trim(Replace(MyArray(i), "Move in Date:", ""))
End If
'Address:
If InStr(1, MyArray(i), "Address:", vbTextCompare) Then
strTemp = Split(MyArray(i), "Address:")
Address = Trim(Replace(MyArray(i), "Address:", ""))
End If
Next i
'~~> Create a new instance of Excel
Set oXLApp = New Excel.Application
'~~> Open Excel File
Set oXLBook = oXLApp.Workbooks.Open(strFileName)
'~~> Work with First Workbook
Set oXLSheet = oXLBook.Worksheets(1)
oXLApp.Visible = False
oXLApp.DisplayAlerts = False
oXLApp.ScreenUpdating = False
LastRow = oXLSheet.Range("A" & oXLApp.Rows.Count).End(xlUp).Row + 1
'~~> Index Number
oXLSheet.Range("A" & LastRow) = SenderName
oXLSheet.Range("B" & LastRow) = SSN
oXLSheet.Range("C" & LastRow) = RentAmount
oXLSheet.Range("D" & LastRow) = MoveInDate
oXLSheet.Range("E" & LastRow) = Address
LetsContinue:
oXLApp.DisplayAlerts = True
oXLApp.ScreenUpdating = True
'~~> Close and save
oXLBook.Close savechanges:=True
'~~> CLEANUP (VERY IMPROTANT)
Set oXLSheet = Nothing
Set oXLBook = Nothing
oXLApp.Quit
Set oXLApp = Nothing
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
<This is an exact  duplicate of this: https://www.experts-exchange.com/questions/28221319/How-to-parse-email-body-to-Microsoft-Access.html>
<Not quite but close now I am using outlook and access 2013 and I reworded a little. >
...
Then why not close that question first...?
Then post the working code here...
<Not quite but close now I am using outlook and access 2013 and I reworded a little. >
...
Then why not close that question first...?
Then post the working code here...






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I tried closing the first post here. Sorry.
So this is all I am going to get is a scolding because I posted it twice. What more than sorry would you like so that I can get some help here.
No scolding...
It's just that it confuses the experts and we don't know what question to reply to...
But as far as your question is concerned, ...what you are asking here can be done, but it is not easy, especially for someone new to VBA coding.
But there may be some good news here...
;-)
If you are using Access 2007 or higher you can use the "Email Data Collection" feature to get this data into Access directly.
No code needed at all.
See here for more info:
http://office.microsoft.com/en-us/access-help/demo-collect-data-in-access-2007-by-using-e-mail-HA010252713.aspx
...and here:
http://office.microsoft.com/en-us/access-help/collect-data-by-using-e-mail-messages-HA010015427.aspx
There are other videos on Youtube as well...
;-)
JeffCoachman
It's just that it confuses the experts and we don't know what question to reply to...
But as far as your question is concerned, ...what you are asking here can be done, but it is not easy, especially for someone new to VBA coding.
But there may be some good news here...
;-)
If you are using Access 2007 or higher you can use the "Email Data Collection" feature to get this data into Access directly.
No code needed at all.
See here for more info:
http://office.microsoft.com/en-us/access-help/demo-collect-data-in-access-2007-by-using-e-mail-HA010252713.aspx
...and here:
http://office.microsoft.com/en-us/access-help/collect-data-by-using-e-mail-messages-HA010015427.aspx
There are other videos on Youtube as well...
;-)
JeffCoachman

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Jeff,
I am unable to use this particular function because we get these emails randomly we don't solicit for them. However they do have to adhere to a predetermined format when sending us such emails. I am new to coding vba not in the use of it.
The format we receive the email in is as follows.
The subject will always be "Move in a Resident"
Applicant Details:
-- Doe, John D Â SSN: 000000000
Rent Amount: $700.00
Move In Date: 08/03/2013
Address:
3701 Cimarron Blvd Corpus, Christi, TX 78414
The fields in Microsoft Access Database "Move In" Table "Move In"are
Name
SSN
MoveInAddress
Rent
MoveInDate
If each field and answer were on one line I am pretty sure I would be able to code it.
Please help in any way you can.
Connie
I am unable to use this particular function because we get these emails randomly we don't solicit for them. However they do have to adhere to a predetermined format when sending us such emails. I am new to coding vba not in the use of it.
The format we receive the email in is as follows.
The subject will always be "Move in a Resident"
Applicant Details:
-- Doe, John D Â SSN: 000000000
Rent Amount: $700.00
Move In Date: 08/03/2013
Address:
3701 Cimarron Blvd Corpus, Christi, TX 78414
The fields in Microsoft Access Database "Move In" Table "Move In"are
Name
SSN
MoveInAddress
Rent
MoveInDate
If each field and answer were on one line I am pretty sure I would be able to code it.
Please help in any way you can.
Connie
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.