Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Document Index    Comments List
Pending Approval    Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 

Anonymous 
 
Alex Hedley  @Reply  
           
4 years ago
If you open the .msg file in notepad what happens?
Sandra Truax  @Reply  
          
4 years ago
If I open it in notepad I get [gibberish removed by Richard]
Alex Hedley  @Reply  
           
4 years ago
Sub ReadMsg()
    Dim objOL As Outlook.Application
    Dim Msg As Outlook.MailItem
    Msgbox "If you get an error, try the Late Biding right under this (need to be uncommented)"
    'Dim objOL As Object
    'Dim Msg As Object

    Set objOL = CreateObject("Outlook.Application")
    inPath = "C:\PATH. . ."

    thisFile = LCase(Dir(inPath & "\*.msg"))
    Do While thisFile <> ""

        'Set Msg = objOL.CreateItemFromTemplate(thisFile)
        'Or
        'Set Msg = objOL.OpenSharedItem(thisFile)
        'Set Msg = GetNameSpace("MAPI").OpenSharedItem(thisFile)

        'Eventually with Shell command (here for notepad)
        'Shell "notepad " & thisFile
        Set Msg = objOL.Session.OpenSharedItem(thisFile)

        Msg.display

        MsgBox Msg.Subject
        thisFile = Dir
    Loop

    Set objOL = Nothing
    Set Msg = Nothing
End Sub


https://stackoverflow.com/a/30910159/2895831
Sandra Truax  @Reply  
          
4 years ago
Thank you Alex. I will give this a try.
Kevin Yip  @Reply  
     
4 years ago
Hi Sandra, .msg files are specially formatted files that can only be opened with Outlook.  So you need to have Access "talk" to Outlook via a process called "automation", then you can retrieve the email's content with VBA.  See picture below.  First you need to enable "Outlook Object Library" in the VBA editor's list of "references".  Then you a write a little VBA procedure as shown, not terribly difficult.  The email body is stored in "m.Body" in my example.  One caveat is that if the email is in HTML format, you'll get a bunch of HTML codes instead of plain text.
Kevin Yip  @Reply  
     
4 years ago

Sandra Truax  @Reply  
          
4 years ago
Thank you so much Kevin! I'm fixing to give this a try!
Sandra Truax  @Reply  
          
4 years ago
Kevin Yip,  you're amazing!  This worked! Now I just have to incorporate the code into the original code Richard has for the text and word documents. I'm so excited!  :)  Thank you again!
Gary Marks  @Reply  
    
4 years ago
This is great!  One question on brining in the msg/mail text:  When I use the code above and set the textbox to equal the value of m.Body, it works but the text comes in as a continuous block (hard to read; looses original formatting/spacing).  But when I just copy the body of the text from the email and paste it into the same text box it comes in with all the proper formatting that makes it much easier to read (looks more like the original email).  Is there a way of copying and pasting the text with vba like we did with the word doc?
Kevin Yip  @Reply  
     
4 years ago
Hi Gary, your email is apparently in HTML format, and for Access to retain the format, you need to use:

This:   m.RTFBody
Instead of this:   m.Body

to retrieve the body's content.

Your textbox needs to be formatted for rich text, of course, in order to show the formatting.

Still, this method won't duplicate the look or content exactly.  Even copying and pasting won't, because an Access textbox simply can't recreate an entire webpage, which is what an HTML email is.  It can recreate some basic settings such as font face and size.  But some HTML elements will simply be discarded, such as images, links, buttons, etc., or turned into something else.
Sandra Truax  @Reply  
          
4 years ago
Thank you Gary and Kevin. I was having the same issue, but just didn't follow up on it with another question. Sure glad you did Gary, and thank you Kevin for the solution!
Gary Marks  @Reply  
    
4 years ago
Yes, thanks Kevin!!
Gary Marks  @Reply  
    
4 years ago
Hi Kevin, one follow-up.  This works great, but I find that when I set it up to add additional files (e.g., notes = notes & m.RTFBody) to my text field (Word files or additional msg), it either replaces the old msg text (so only the most recently added text appears) or the old msg text turns to unreadable characters.  I can get it to work for adding multiple word docs to my text field, just not msg.  Any thoughts?
Kevin Yip  @Reply  
     
4 years ago
Hi Gary, you cannot use string concatenation for data that are not in plain text, such as "RTFBody", which contains rich text codes.  Even if "notes" is a rich text field in Access, it still won't work because Access uses a different kind of rich text format.  If you need to keep adding emails, you may be able to accomplish that with some kind of one-to-many relationship: a table containing multiple child records, each containing one email only, all linked to a parent record.

As I said, email uses actual HTML codes used by websites (that's why some emails would say "Open this email in a browser").  And Access does not.  An Access textbox cannot store a full HTML web page.

If you anticipate things getting more and more complicated in the future (e.g. more features needed to manipulate the emails), I would advise not using Access for this.  The only format Access works best with is plain text.

In my old job, I had an email app made with Access too.  But it was for emails created in Access, in plain text.  For all other email-related tasks such as word-search, sort, archive, etc., I relied on the email apps themselves.  If I had stand-alone email files (.msg., .eml, etc.), I would import them back into email apps instead of involving Access.
Gary Marks  @Reply  
    
4 years ago
Thanks for the explanation, Kevin!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Document Index.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 7/19/2026 6:31:07 PM. PLT: 1s