Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save outlook e-mail via access 1

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
Hi

I'm looking a way to save via Access an e-mail received in Outlook to a folder as determined in an open Access form.

The code I'm trying is along the lines of:

Code:
Sub SaveEmail()
    Dim myOlApp As New Outlook.Application
    Dim objEmail As Outlook.MailItem
    
    set objEmail = ?????????????????
    
    With objEmail
    
    .SaveAs Forms("formname").Controls("docfolder").Value & "\Email - Draft Report.htm", olHTML

End Sub

The problem is what to put in the "set objEmail" line to refer to the active email or window in Outlook.

I have tried using the "ActiveWindow" command without any success.

Is the above code along the right lines or am I way off the mark.

Thanks in advance

AL
 
Some code...

Code:
Dim OutApp As Outlook.Application
Dim OutNameSpace As Outlook.NameSpace
Dim OutFolder As Outlook.Folder
Set OutApp = CreateObject("Outlook.Application")
Set OutNameSpace = OutApp.GetNamespace("MAPI")
Set OutFolder = OutNameSpace.GetDefaultFolder(olFolderInbox)

That will get you the Inbox folder. You should be able to manipulate the mailitems from there. I'm just not sure how you are identifying which e-mail you want to save.
 
Thanks for that.

As regards identifying the e-mail I want to save - I was thinking of having it open in it's own window and getting Access to save the active window?

Does that make sense?

AL
 
Just to add - I get a "user-defined type not defined" error on the "Dim OutFolder As Outlook.Folder" line in the above code.

AL
 
The error is caused by a missing reference to the Outlook library, Tools>References...

TomCologne
 
I have "Microsoft Outlook 11.0 Object Library" and "Microsoft Office Outlook View Control" installed. Which other reference(s) do I need to install?

Thanks

AL
 
That was old code... In a version I have with Outlook 11.0 object library I have the following instead.

Code:
     Dim OutFolder As Outlook.MAPIFolder

I also have things like

Code:
    Dim OutItems As Items
    Dim Outmailitem As Object
    Dim lngCntItems As Long
    Set OutItems = OutFolder.Items
    lngCntItems = OutFolder.Items.Count
    While lngCntItems > 0
        Set Outmailitem = OutItems(lngCntItems)
        lngCntItems = lngCntItems - 1
    Wend


But I am processing electronically sent e-mail. In the full version I save attachments, modify the saved excel documents and import them. I also move the mailitem in each loop iteration through a separate function.

Honestly, I do not know how to grab the active message... I think you have to move into the world of VBScript and doing it in Outlook. I can't say for sure as I have never needed to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top