Connecting Tech Pros Worldwide Forums | Help | Site Map

Access & Outlook

Newbie
 
Join Date: Dec 2007
Posts: 15
#1: Jul 3 '08
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?

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#2: Jul 3 '08

re: Access & Outlook


can you pass more information please.
Newbie
 
Join Date: Dec 2007
Posts: 15
#3: Jul 3 '08

re: Access & Outlook


Quote:

Originally Posted by debasisdas

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.
Newbie
 
Join Date: Dec 2007
Posts: 15
#4: Jul 3 '08

re: Access & Outlook


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
Reply