Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Access & Outlook

Question posted by: IceBower (Newbie) on July 3rd, 2008 10:27 AM
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
debasisdas
Moderator
6,576 Posts
July 3rd, 2008
11:29 AM
#2

Re: Access & Outlook
can you pass more information please.

Reply
IceBower's Avatar
IceBower
Newbie
15 Posts
July 3rd, 2008
12:05 PM
#3

Re: Access & Outlook
Quote:
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.

Reply
IceBower's Avatar
IceBower
Newbie
15 Posts
July 3rd, 2008
02:10 PM
#4

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
Reply
Not the answer you were looking for? Post your question . . .
189,891 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Visual Basic Forum Contributors