By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Access & Outlook

P: 15
Hi all,

Im creating a database which has a table linked to an email account. so far i can only get the table to show wether or not an email has an attachment but i cant find away of opening/importing them.

Anyone know how?
Jul 3 '08 #1
Share this Question
Share on Google+
3 Replies


debasisdas
Expert 5K+
P: 8,127
can you pass more information please.
Jul 3 '08 #2

P: 15
can you pass more information please.
What im ideally looking for is some Access code that will allow me to detach the files from emails (linking them using the table mentioned) and save them to a local drive.
Jul 3 '08 #3

P: 15
This could do with tidyign up a bit but it seems to do the job!


Expand|Select|Wrap|Line Numbers
  1. Dim oOutlook As Outlook.Application
  2. Dim oNs As Outlook.NameSpace
  3. Dim oFldr As Outlook.MAPIFolder
  4. Dim oAttachments As Outlook.Attachments
  5. Dim oAttachment As Outlook.Attachment
  6. Dim iMsgCount As Integer
  7.  
  8. Dim oMessage As Outlook.MailItem
  9.  
  10. Dim iCtr As Long, iAttachCnt As Long
  11.  
  12. Dim sFileNames As String
  13. Dim aFileNames() As String
  14.  
  15.  
  16. 'get reference to email folder
  17. Set oOutlook = New Outlook.Application
  18. Set oNs = oOutlook.GetNamespace("MAPI")
  19. tolfolder = "Mailbox - Bower, Phil X" 'Top folder
  20. myfolder = "Important" 'email folder
  21. Set oFldr = oNs.Folders(tolfolder).Folders(myfolder)
  22.  
  23.  
  24.  
  25. Debug.Print "Total Items: "; oFldr.Items.Count
  26. Debug.Print "Total Unread items = " & oFldr.UnReadItemCount
  27.  
  28.  
  29. For Each oMessage In oFldr.Items
  30.  
  31.     With oMessage
  32.         'basic info about message
  33.         If .UnRead = True Then
  34.             Debug.Print .To
  35.             Debug.Print .CC
  36.             Debug.Print .Subject
  37.             Debug.Print .Body
  38.             iMsgCount = iMsgCount + 1
  39.             With oMessage.Attachments
  40.                 iAttachCnt = .Count
  41.                 If iAttachCnt > 0 Then
  42.                     For iCtr = 1 To iAttachCnt
  43.                         'UID will need replacing with unique identifier for record in DB
  44.                         .Item(iCtr).SaveAsFile "C:\" & UID & "\" & .Item(iCtr).FileName
  45.                     Next iCtr
  46.                 End If
  47.             End With
  48.             .UnRead = False
  49.         End If
  50.     End With
  51. Next oMessage
  52.  
  53.  
  54. End Sub
Jul 3 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.