PDA

View Full Version : save last sent email from outlook after click a button in access



lucass3231
08-04-2016, 07:52 AM
I am curious if it is possible to start macro from access that save last sent email from outlook to local folder? I have something like that at this moment but it saves all emails when sending. Please advise. now I past it into vb in access but got an error 'Method or data member not found' and highlighted first line:

Code:
PrivateSub Command82_Click()
Code:

Dim myNameSpace As Outlook.Namespace
Dim myFolder As Outlook.Folder
Dim myNewFolder As Outlook.Folder
Dim myItem As Outlook.MailItem
Dim myCopiedItem As Outlook.MailItem
Dim myItems AsObject
Dim savePath AsString

Set myNameSpace = Application.GetNamespace("MAPI")

Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)

Set myItems = myFolder.Items
myItems.Sort ("[SentOn]")


Set myItem = myItems.GetLast

savePath ="C:\Users\ll59205\Desktop\New folder\archiwum"'## Modify as needed
savePath = savePath & m.Subject & Format(Now(),"yyyy-mm-dd-hhNNss")
savePath = savePath &".msg"

Debug.Print myItem.CreationTime
myItem.SaveAs savePath, OlSaveAsType.olMsg
EndSub

jonh
08-04-2016, 03:32 PM
Set myNameSpace = Application.GetNamespace("MAPI")

Application in Access would be the Access application, not Outlook. I'd guess it should be

Set myNameSpace = outlook.GetNamespace("MAPI")

For issues specifically related to Outlook, you'd probably do better posting in the Outlook forum.

gmayor
08-04-2016, 09:36 PM
See your duplicated message in the Outlook forum http://www.vbaexpress.com/forum/showthread.php?56796-save-last-sent-email-from-outlook-after-click-a-button-in-access
Please do not duplicate threads without cross posting correctly.