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!

Saving e-mail attachments

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
Hi

I used the code below in Access 2002 to save an Outlook e-mail and any attachments to a specified folder. I recently upgraded to Access 2010 and have found that the part of the code that saves the attachments (in bold below) no longer works. I get an error message Compile error: Method or data member not found. If I "rem" out that part of the code, the e-mail itself saves OK.

Any advice would be greatly appreciated.

Thanks

AL

Code:
If Me.docfolder = "" Then GoTo nofolder

Dim ol As Outlook.Application
Dim ns As Namespace
Dim folder As MAPIFolder
Dim i As Integer
Dim email As MailItem
Dim emailsubject As String
Dim emailname As String
Dim email1 As MailItem
Dim att As Attachment

Set ol = CreateObject("outlook.application")
Set ns = ol.GetNamespace("MAPI")
ns.Logon

Set folder = ns.GetDefaultFolder(olFolderInbox)

Set email = folder.Items.GetLast

Me.tbl_Correspondence_subform2.SetFocus
DoCmd.GoToRecord , , acNewRec
         
         Me.tbl_Correspondence_subform2!Date = email.ReceivedTime
         
         emailname = Forms!Form1!docfolder & "\Email " & Me.tbl_Correspondence_subform2!ID & ".msg"
                        
         email.SaveAs emailname, olMSG
              
         Me.tbl_Correspondence_subform2!Details = "From: " & email.SenderName & " - " & email.Subject
         Me.tbl_Correspondence_subform2!Link = "Email#" & emailname & "#"
              
         [b]For Each att In email.Attachments
         
         att.SaveAsFile Forms!Form1!docfolder & "\" & att.FileName
                  
         Next att[/b]

Exit Sub

nofolder:
MsgBox "Document folder has not been specified.", vbInformation, "Cannot continue"
Me.Document_folder.SetFocus

End Sub
 
Which line of code is highlighted ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The following code doesn't appear to work:

Code:
 For Each att In email.Attachments
         
         att.SaveAsFile Forms!Form1!docfolder & "\" & att.FileName
                  
         Next att
 
You've already showed those 3 lines.
Again, which line of code is highlighted when you get the Compile error.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry

The error is on

Code:
att.SaveAsFile Forms!Form1!docfolder & "\" & att.FileName

If I "rem" out the above line. The error is then shown on

Code:
For Each att In email.Attachments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top