473,623 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract data from outlook email body

266 Contributor
Hi Everyone,

I have linked my outlook folder to a table in access. My problem is the body of the email is in a field called contents. I need to extract certain information from the body of the email or contents field. For example, within the body of the email there is a start date, laid out in the email as "Start Date/Time: 1/1/18 at 7:00". I need to be able to extract that piece of information for queries and the like. Perhaps making it its own field? I am new at working with outlook imports and appreciate any feedback. Thank you!
Jul 17 '19 #1
6 1788
NeoPa
32,566 Recognized Expert Moderator MVP
If that's really the format of your date and time then you should look at the basic formats on how your version of Windows is configured. I thought 2-digit years went out at the end of the last millennium, but maybe there are still those yet to learn their lessons. Times in non 24-hour format need an AM or PM indicator.

All that said, and I will assume you're using the American date format as your example data leaves that unclear, you could use something like the following to get a full Date/Time value from that string :
Expand|Select|Wrap|Line Numbers
  1. StartPoint: CDate(Replace(Replace([Start Date],'Start Date/Time: ',''),' at ',' '))
Obviously this will only work as required if the information you've included is accurate. If any names need to be changed you'll need to do that before testing.
Jul 17 '19 #2
didacticone
266 Contributor
I appreciate your help, and apologies for not making this clear. the emails I am receiving are from an outside company in regards to work that needs to be completed by my company. I do not have control over how they format anything in the body of their emails. I am just trying to work with what I am given. The body of the email contains a lot of data, the exact row in the body of the email looks like this "Start Date/Time: 07/23/19 At 08:00 Expiration Date: 09/19/19" I am not concerned about format, I am looking to extract that, or for that matter, learn how to extract any information from the body of an email into usable data for queries, etc. I would like to be able to query by that date and access would pull up everything with that date as a result. With it all condensed in the one field I dont believe i can do that correct? Thank you.
Jul 17 '19 #3
NeoPa
32,566 Recognized Expert Moderator MVP
I'm surprised by your response. I showed in my earlier post how it could be done for the format of string that you posted originally. It sounds like you didn't try that.

It may be that, as you now say there's more data in the string you're working from than originally specified, we may need to ensure that's properly handled. Other than that though, what I posted earlier should get you there with tweaks depending on exactly how the data is presented to you. All I know at the moment is that there's more data after that containing the date and time, but apparently that's still at the start. That's fine for the start of it but how can we recognise the end when the lengths of the dates themselves can vary? You've not told us much about the format of the data itself or what Field it's in for instance, so finding a way process it will be difficult. What we're looking for to help determine how to approach this is what data can be relied on after the date string. It clearly isn't formatted in a way to make life easy for you. That's why two digits for days, months, hours and generally four digits for years is used so heavily. It displays in a way that's easy to read from lists and it's much easier to process and convert to & from text. Obviously whoever prepared the format of your data didn't appreciate those subtleties - and you're left with the fallout. Nice.

There are ways to handle most things, but until you give more details of what's where it's very hard to know what might be appropriate for your situation.
Jul 18 '19 #4
didacticone
266 Contributor
I understand what you provided, but yes the issue is, it is the body of an email, and as i said in my first post when imported over, the body of an email goes into a field that is auto created called contents. you are correct that the people providing this information are not concerned with making my life easier, but i have certain requirements that i have to follow and figuring this out would certainly make everything easier. What i did not explain fully enough was that there is text before the line with the start date and text after the line. It also is not a consistent amount of spaces. every email has certain variables that will move where that start time/date is. so basically i was trying to see if there is a code to use certain words as a starting point, perhaps some combination of the mid or instr function? Or maybe it is better to not link the email account directly but use vba to import manually with a command button? again working with importing from outlook is new to me so im just looking for some advice, because as you said i am most certainly left with dealing with the fallout lol... thanks for your help
Jul 18 '19 #5
NeoPa
32,566 Recognized Expert Moderator MVP
There certainly are ways. I was looking to you for information on what you CAN rely on. The text immediately beforehand is important info. As yet we have no knowledge of what must come afterwards - if indeed there is anything that predetermined.

Obviously the easiest way to handle this is to provide a Public Function from a Standard Module that does the heavy lifting for you. That way you can use VBA features that are unavailable to SQL directly (When I say SQL here I'm referring to The Expression Service (ES) which is used to handle calls that are not native SQL from either the Jet or ACE SQL engines). The easiest approach, or maybe just the first that comes to my mind, is to use Split(), but this relies on the ability to handle array references. Easy in VBA. Unsupported by the ES.

If there were something else known, and 100% reliable, about the data we could look at a SQL/ES-only solution. On the other hand, if there may be a number of different requirements that you will have to handle across the [Contents] field (Sorry. From your earlier use of the word (contents) I was under the impression you were using it as a noun rather than a proper noun, IE a general descriptive term rather than the name of a Field per se).

It may well be that you would be best served by a Function, as described earlier, that will take the [Contents] Field data as well as another parameter indicating which result is required, and return data that matches the specified requirement. As a basic start you could have :
Expand|Select|Wrap|Line Numbers
  1. Public Function Translate(strContents As String, strReturn As String) As Variant
  2.     Dim strWork As String
  3.  
  4.     Select Case strReturn
  5.     Case "StartDate"
  6.         'Assumes "." comes after the relevant text in [Contents].
  7.         strWork = Split(Split(strContents, "Start Date/Time: ")(1), ".")(0)
  8.         Translate = CDate(Replace(strWork, " at ", " "))
  9. '    Case "..."
  10. '        Translate = ...
  11.     Case Else
  12.         Translate = Null
  13.     End Select
  14. End Function
Notice the return value is declared as Variant so when no value is found then it can return Null, but it also allows Dates and other Variant types to be used as return values of the Function.

NB. I wasn't being unhelpful before. It's just that many don't understand how important information is when considering how best to handle it. Slightly different environments (or data structure) can mean great differences to how best it should be handled. As a general rule I will always avoid the Public Function approach as it is not very performant for large quantities of records. On the other hand it's very flexible and powerful. From what we know so far it's the only approach that we know can work.
Jul 18 '19 #6
Rabbit
12,516 Recognized Expert Moderator MVP
I think the misunderstandin g here is the word "format"

I presume the OP is referring to visual formatting. i.e. italics, bold, font size, etc.

NeoPa is referring to data formatting. e.g. Start Date/Time vs Start Time/Date
Jul 19 '19 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5945
by: Chuck Farah | last post by:
I am unsuccessfullly trying to display an outlook email from a vb web forms (.net) outlook 2002 #1. is it possible to use outlook client email from a web form using the outlook object model within vb .net for web forms? #2. If not what is recommended (SMTP has problems if the address are not correct). I also have used the Mailto: but am having problems passing the body with formating
1
2670
by: Brian | last post by:
I have a project that I built that takes data from a recordset and then send an email to appropriate person. This process is using Access 2K and Outlook 2K. The email is going out as a RTF email and I want to format some of the Fonts sizes and attributes like Bold or Italic. I can format the dates and numbers, but can't seem to get the Font Size and Color to change in code. Can someone please give me some tips on how to get this done. ...
0
1495
by: David Lao | last post by:
Hi All, I need a way to extract Data value from the Outlook form when the new mails arrive. The data fields are provided. Thanks. David
1
10057
by: joshua | last post by:
Is there a way to set the FROM name (the name the recepient sees as the one who sent the email) when using Access to create an Outlook email message? (Using MS-Office 2000 SP3) We set up an anonymous account to send survey messages to our customers in the company-wide address book, but can I set the message to be sent from that account in code? It always defaults to the normal (default) "From" name Outlook sender. Here's my code so...
0
2143
by: VP | last post by:
g'day, i am posting a problem i have encountered with creating an email using outlook through some basic c# code. the problem arises when using different email editors in outlook. At the moment i am using outlook 2000. Outlook can be configured to use the default outlook email editor or use ms word as the email editor in outlook. The sample code below simply creates an email with a hyperlink. The problem I am facing is that when...
5
7203
by: xin.yadong | last post by:
Is there a way to create an New Outlook Email from an ASP.NET application? I can not use "mailto:", since it is only support a string less than 512. I have find a good way from link : http://zones.advisor.com/doc/17330 , that thread show how to create a new appointment instead of email. but I have no idea about the format of a new email. Does any one know the format of a new outlook email i.e. Response.ContentType = "text/XXXXXX"...
9
12190
Boxcar74
by: Boxcar74 | last post by:
I think this is a little crazy but I supposed to figure out how to get the body of an email message (Outlook) into an Access DB table, with little to no effort :) Here is the deal I receive email with the results from an online survey and I need to get the data into Access for reporting proposes. ------------------------------------- I can get it in Access with a copy/ paste to Excel the use “Text to Columns” Then “Pate Special”/...
2
1834
by: tgmcnaughton | last post by:
I'm brand new to server-side scripting. I don't even know if javascript can do this. I would like a script running on my server to periodically login to and check my email account and each time it finds a new message with a particular identifying subjectline, it should extract the body of the message into a text variable and append it to an existing file already on the server. I can handle the parsing and the appending, but I don't know...
2
4586
by: =?Utf-8?B?U2hydXRpIERlc2hwYW5kZQ==?= | last post by:
I am developing an application in vb.net 2005 to send email via outlook. The mail body contains key - value pairs like Account Number : 232323 CRS Number : 872732 Name : John the problem is that this alignment is not retained when the mail is sent through outlook although i"ve used it in code(using tab chars and padright). The spaces are not retained,so the colons do not come ina line.
11
33467
by: ryaanmichael | last post by:
Is there a way to insert data/information from a report into the body of an Outlook email message? I want the VBA code to pull the data from my report, input it into the body of my email message, and then send, without using any attachments. Thanks for any assistance!
0
8217
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4067
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2590
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1467
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.