Results 1 to 6 of 6

Thread: Help!!!

  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Unanswered: Help!!!

    I am trying to have Access open MSOutlook and retrieve an attached file from an e-mail and save it to my desktop.
    What I have below continues to give me an error saying the Inbox is empty. Any ideas? Any better code to do this with?


    Public Function SaveAttachmentfiles()

    Dim MyObject As Object
    Dim myApp As Object
    Dim myAttachments As Object
    Dim myNamespace As Object
    Dim myFolder As Object
    Dim myMail As Object
    Dim s_Path As String
    s_Path = "c:\windows\desktop\xstmcci.csv"


    Set myApp = CreateObject("Outlook.Application")
    Set myNamespace = myApp.GetNamespace("MAPI")
    Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
    Set myMail = myFolder.Items
    Set myAttachments = myMail.Attachments
    With myMail
    myAttachments.Item.SaveAsFile s_Path
    End With


    End Function

    Thank you in advance
    HCD

  2. #2
    Join Date
    Dec 2003
    Location
    Toronto, Ont. Canada
    Posts
    238

    Re: Help!!!

    Originally posted by hcd1234
    I am trying to have Access open MSOutlook and retrieve an attached file from an e-mail and save it to my desktop.
    What I have below continues to give me an error saying the Inbox is empty. Any ideas? Any better code to do this with?


    Public Function SaveAttachmentfiles()

    Dim MyObject As Object
    Dim myApp As Object
    Dim myAttachments As Object
    Dim myNamespace As Object
    Dim myFolder As Object
    Dim myMail As Object
    Dim s_Path As String
    s_Path = "c:\windows\desktop\xstmcci.csv"


    Set myApp = CreateObject("Outlook.Application")
    Set myNamespace = myApp.GetNamespace("MAPI")
    Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
    Set myMail = myFolder.Items
    Set myAttachments = myMail.Attachments
    With myMail
    myAttachments.Item.SaveAsFile s_Path
    End With


    End Function

    Thank you in advance
    HCD
    Save an attached file from which email?... What identifies this particular email from any other?... A specific subject line perhaps?... What I see here is you setting myMail to "myFolder.Items"... but not specifying which item...

  3. #3
    Join Date
    Feb 2004
    Posts
    3
    When the email comes in, it's one email each evening, I have it going to a subfolder. So, there would be only one email. How do I tell it to look at the subfolder and the one email in that folder. Then how do I delete the mail after I have saved the attached file?
    Thank you for your help.

  4. #4
    Join Date
    Dec 2003
    Location
    Toronto, Ont. Canada
    Posts
    238
    Originally posted by hcd1234
    When the email comes in, it's one email each evening, I have it going to a subfolder. So, there would be only one email. How do I tell it to look at the subfolder and the one email in that folder. Then how do I delete the mail after I have saved the attached file?
    Thank you for your help.
    This'll work... I just tested it...
    Code:
    Public Function SaveAttachmentfiles()
    
    Dim MyObject As Object
    Dim myApp As Object
    Dim myAttachments As Object
    Dim myNamespace As Object
    Dim myFolder As Object, myNewFolder As Object
    Dim myMail As Object
    Dim s_Path As String
    s_Path = "C:\Documents and Settings\treaspa\Desktop\"   'change to your path...
    
    
    Set myApp = CreateObject("Outlook.Application")
    Set myNamespace = myApp.GetNamespace("MAPI")
    Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
    Set myNewFolder = myFolder.Folders("testing")   'change to your subfolder name
    Set myMail = myNewFolder.Items(1)
    Set myAttachments = myMail.Attachments
    With myMail
    myAttachments.Item(1).SaveAsFile s_Path & myAttachments.Item(1).DisplayName
    End With
    myMail.Delete
    
    End Function
    Now this is assuming a couple of things...
    1) Your subfolder is a subfolder of Inbox
    2) You can save the attached file as the name and type it comes in as in the email

    Let me know how it goes...

    HTH

  5. #5
    Join Date
    Feb 2004
    Posts
    3
    First, thank you very much for your help. I really appreciate it.
    I'm sure the code will work, although it does not work on my computer. I have had this happen before where code very similar to this worked on other computers but not mine. Which is fine, since it will not be running from my personal pc. I'll let you know tomorrow if it doesn't work on the other pc.
    I do have one other question. If I were to run this for one subfolder and then run it again, right after for a different subfolder, would I have to reset anything?
    Also, do you have any ideas why some code will not run on my pc, yet some will? Also, I have Outlook and Outlook Express, yet I have set both up with the same subfolders, could this be a problem? The error I get is the same. The Inbox is empty.
    Thank you again, it's greatly appreciated.
    HCD

  6. #6
    Join Date
    Dec 2003
    Location
    Toronto, Ont. Canada
    Posts
    238
    Originally posted by hcd1234
    First, thank you very much for your help. I really appreciate it.
    I'm sure the code will work, although it does not work on my computer. I have had this happen before where code very similar to this worked on other computers but not mine. Which is fine, since it will not be running from my personal pc. I'll let you know tomorrow if it doesn't work on the other pc.
    I do have one other question. If I were to run this for one subfolder and then run it again, right after for a different subfolder, would I have to reset anything?
    Also, do you have any ideas why some code will not run on my pc, yet some will? Also, I have Outlook and Outlook Express, yet I have set both up with the same subfolders, could this be a problem? The error I get is the same. The Inbox is empty.
    Thank you again, it's greatly appreciated.
    HCD
    Well... This code will only work with Outlook... not Outlook Express... and Outlook would have to be your default email client... and you have to make sure that you are referencing the Outlook Object Library...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •