Solved

Saving a copy of an email created with Outlook.MailItem after it has been sent.

Posted on 2006-06-19
5
669 Views
Last Modified: 2012-06-27
I have an access database with a form that has a button that i use to automatically create an email with some standard text for the body.

Sometimes my users would like to be able to edit the body before it is sent, so instead of automatically sending it I just display it and let them send it when they are finished.

I am trying to create a copy of the email to save in an extra folder in outlook. I can make of copy of the email after I initially create it but I don't have any of the extra comments that they would input, so i need to copy it after they send it.

Is there a way to catch the send event from inside my access database so i can make a copy of the mailitem object. (i.e. creating an object with events)

I have also thought about creating a rule in outlook that would save any email from the sent folder if it had my pregenerated heading but I would like to accomplish this through code so any new users can automatically use the program without me needing to remeber to set up outlook with the email rule.

I'm currently trying to save the EntryID of the mailitem so i can use it later to cycle through the sent folder and pull out any emails they sent from my program. I haven't gotten far with this in code but the logic flaw i come accross is decideing when i should run the method that does this.

Any help, suggestions and comments is greatly appreciated. Below is a copy of my code.

Dim appOutlook As Outlook.Application, ns As NameSpace
Dim olFolder As Outlook.MAPIFolder, olSent As MAPIFolder
Dim olMail As Outlook.MailItem, olMailCopy As Outlook.MailItem

Set appOutlook = New Outlook.Application
Set ns = appOutlook.GetNamespace("MAPI")
Set olMail = appOutlook.CreateItem(olMailItem)
Set olFolder = ns.GetDefaultFolder(olFolderInbox).Folders("SaveFolder")
Set olSent = ns.GetDefaultFolder(olFolderSentMail)

With olMail    
     .To = rsMgr![User_Email]
     .Subject = "# " & Me![Num] & " Standard Heading"
     .Body = rsMgr![StandardBodyText]
     .Display
     intMsgID = .EntryID
End With

Set olMailCopy = olMail.Copy  ' This is the previous code that saves the copy before they have a chance to edit the body text
olMailCopy.Move olFolder

For Each olMail In olSent.Items    ' This is the code that i was working with to cycle through the sent box but I have to find a way to run it after they send the email
     If olMail.EntryID = intMsgID Then
          Set olMailCopy = olSent.Items()
     End If
Next
           
End Sub

Thanks,
Jason
0
Comment
Question by:CanIJay
  • 2
  • 2
5 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 16935680
Hi Jason,
Interesting what you're trying to do. And this may seem rather off point, but how about making your e-mail address a BCC and simply have the e-mail delivered to your inbox. You can create a rule then to move the e-mail to your save folder.
J
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 250 total points
ID: 16935734
Why not put a memo field in you DB and then on the a text box bound to that field. Then they type the text in the DB and you just put that in the body of the e-mail as well?
0
 

Author Comment

by:CanIJay
ID: 16935763
I'm trying to avoid using outlook rules to copy the email becuase the user base of my program will switch at any given time to new employees but the mailbox they all share will always be the same. So when a new employee switches roles and begins using my program I may not get notified by the managers and I will be unable to set the rule up on their computer.

If my program was able to directly copy the email to the known folders I won't have to worry about creating the rules on the new computer. I thought of a similar rule set up for the sent items box because my heading would always contain similar terminology so a rule would be easy to pick out my emails.

Thanks for the suggestion
Jason
0
 

Author Comment

by:CanIJay
ID: 16935824
jimpen

I've previously ruled out this method becuase of screen layout and my table structure, but this may be the route that I will have go. I'd still like to see if there are any coding methods that would allow me to watch the send event. I highly doubt it though.

Thanks,
Jason
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 17170461
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now