UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Vba Read Body Of .msg File, Access 2016    
 
   
MrFormula
post Sep 11 2019, 09:17 PM
Post#1



Posts: 608
Joined: 28-May 05



Hello,
I am looking for a way to Drag and drop an email on a text box and have it save the .msg file to my hard drive... I have this working from some code I found on https://www.tek-tips.com/viewthread.cfm?qid=1786502.

My new challenge is I would like to extract some of the data,
Email, and the first paragraph of the body of the email.
I want to be able to quickly "preview" the message before I open the individual file.

Thanks for the help
Go to the top of the page
 
jleach
post Sep 12 2019, 07:19 AM
Post#2


UtterAccess Editor
Posts: 10,145
Joined: 7-December 09
From: St Augustine, FL


Hi,

Looks like the article may have touched on it briefly, but once you have a handle to the mailmessage object, you should be able to use "regular" Outlook Automation to work with the file.

I haven't looked around, but I'm fairly confident that if you look for articles on how to automate reading of outlook messages, you should be able to pair that with the tek-tips code you have now and come up with a full-circle solution.

Hopefully that's a pointer in the right direction?

hth

--------------------
Go to the top of the page
 
DanielPineault
post Sep 12 2019, 07:35 AM
Post#3


UtterAccess VIP
Posts: 6,900
Joined: 30-June 11



It always amazes me how people take free code from people and don't have the respect to keep the function header (which has legally binding copyright)! What does it take?! crazy.gif

Sorry, not directly related to the question or person asking but the code in the Link is mine and not acknowledged. Sad when fellow developer are this disrespectful.

--------------------
Daniel Pineault (2010-2019 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
MrFormula
post Sep 12 2019, 10:35 AM
Post#4



Posts: 608
Joined: 28-May 05



Daniel, I meant no disrespect. I copied the link directly from Tek-Tips to make sure to give full reference to the work that was done.

Please accept my appologies and my deepest gratitude for the work that you shared with the community.

Again Please forgive my error.
Go to the top of the page
 
jleach
post Sep 12 2019, 10:44 AM
Post#5


UtterAccess Editor
Posts: 10,145
Joined: 7-December 09
From: St Augustine, FL


I think he was more upset about the original poster at tek-tips, not you (you wouldn't have known, not your fault)

--------------------
Go to the top of the page
 
DanielPineault
post Sep 12 2019, 10:59 AM
Post#6


UtterAccess VIP
Posts: 6,900
Joined: 30-June 11



MrFormula,

As Jack stated, I'm not in the slightest upset at you.

It's just a sad state that developers can't respect fellow developers. This isn't your doing, as Jack stated you had no way of knowing.

I'm the one who is sorry, I've hijacked your question.

--------------------
Daniel Pineault (2010-2019 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
MrFormula
post Sep 12 2019, 11:47 AM
Post#7



Posts: 608
Joined: 28-May 05



Daniel, No problem. It is nice to be able to "Talk" to you.

Back to the question,
I keep finding code that will loop through all of the messages in outlook and do xyz... I just want to find a way to deal with the File I just saved (using your code) and open that file and grab the first paragraph of text... not exactly a paragraph just a preview of the email.

Any suggestions you have would be most helpful.

Thanks
Go to the top of the page
 
MrFormula
post Sep 12 2019, 11:53 AM
Post#8



Posts: 608
Joined: 28-May 05



This is an example I found on https://www.ozgrid.com/forum/forum/other-so...-excel-workshee
I know it is for excel but I am hoping that the VBA is close so we can use it.
How do I directly address the .msg file [EmailLocation] and process it to extract this information.
By the way if I have to have all the text from the email instead of the first paragraph it wouldn't really bother me.

CODE
    Set outFolder = outNs.GetDefaultFolder(olFolderInbox).Folders("CASINO SURVEY")
    If Not outFolder Is Nothing Then
        For Each outMail In outFolder.Items
            If outMail.Class = Outlook.OlObjectClass.olMail Then
                If outMail.Subject = "TORONTO CASINO COMMUNITY SURVEY" Then
                    Extract_Email_Body outMail.HTMLBody, destCell
                    n = n + 1
                End If
            End If
        Next
        MsgBox n & " email(s) processed"
    End If
Go to the top of the page
 
ADezii
post Sep 12 2019, 11:59 AM
Post#9



Posts: 2,678
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. Loop thru all Mail Items in the Inbox and search for a specific Item, perhaps on Subject.
  2. Prompt the User to ensure that this is indeed the E-Mail that you are looking for.
  3. Save the E-Mail as Text (.txt).
  4. Load the Email, or a portion of it, into a Text Box for review.
  5. Will something along these lines work for you, or am I off base with my assumptions?
Go to the top of the page
 
MrFormula
post Sep 12 2019, 12:11 PM
Post#10



Posts: 608
Joined: 28-May 05



1. Loop thru all Mail Items in the Inbox and search for a specific Item, perhaps on Subject. ... No this is the part I don't like. I only want it to do it to the specific email I have saved... c:\emailLocation\123.msg
2. Prompt the User to ensure that this is indeed the E-Mail that you are looking for.... I am using the code from Daniel above so I already have the exact file I need
3. Save the E-Mail as Text (.txt). ... I want to extract the text an store it in my field TeamMemo
4. Load the Email, or a portion of it, into a Text Box for review. ... as mentioned above Just want to store the Body text in the text box... Well I should also extract the email address as well but my original question was for the Body of the mail.
Go to the top of the page
 
ADezii
post Sep 12 2019, 02:11 PM
Post#11



Posts: 2,678
Joined: 4-February 07
From: USA, Florida, Delray Beach


I am having problems with Access in work, so I wrote this Code in Excel using a UserForm with a Command Button (CommandButton1) and a Text Box named txtMsg. I had to set the MultiLine Property of the Text Box (Test.msg) = True. The Code works quite well in that it will display the Body of the E-Mail in the Text Box. Make any adjustments and give it a try in Access.
CODE
Private Sub CommandButton1_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

'********** USER DEFINED SECTION **********
Const conMSG_PATH = "C:\Test\Test.msg"
'******************************************
  
Set objOutlook = New Outlook.Application
Set objOutlookMsg = objOutlook.CreateItemFromTemplate(conMSG_PATH)

Me![txtMsg] = objOutlookMsg.Body
End Sub

This post has been edited by ADezii: Sep 12 2019, 02:13 PM
Go to the top of the page
 
MrFormula
post Sep 21 2019, 11:56 PM
Post#12



Posts: 608
Joined: 28-May 05



This works perfect.
Thanks
Go to the top of the page
 
ADezii
post Sep 22 2019, 06:42 AM
Post#13



Posts: 2,678
Joined: 4-February 07
From: USA, Florida, Delray Beach


yw.gif , Good Luck with your Project.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th October 2019 - 10:55 PM