Solved

Moving a mail message from inbox to a custom folder

Posted on 1998-12-02
4
158 Views
Last Modified: 2010-08-05
I am writting a VB program that loops thru all the emails in Outlook 97's "Inbox" folder and then moves some to a special folder that I created called "Processed UnitedWay Pledges." I cannot move the emails from the inbox to my special folder. Does anyone know how I might accomplish this task? Everything else is working fine.
Thanks!
0
Comment
Question by:beaumont
  • 2
  • 2
4 Comments
 

Author Comment

by:beaumont
ID: 1447887
Edited text of question
0
 

Author Comment

by:beaumont
ID: 1447888
Edited text of question
0
 
LVL 2

Accepted Solution

by:
cedricd earned 50 total points
ID: 1447889
*** Login Function Outlook_LOGIN() As Boolean    On Error GoTo Outlook_Login_Err
        Set theApp = CreateObject("Outlook.Application")
    Set theNameSpace = theApp.GetNamespace("MAPI")    MAILBOX_STATE = 200    
    Exit FunctionOutlook_Login_Err:    Login_Outlook = False    Exit Function
End FunctionFunction Outlook_SaveAttachment(Location As String)
    On Error GoTo Outlook_SaveAttachment_Err    
    Set myAttachments = InboxFolder.Items(EachItem).Attachments
    myAttachments.Item(EachItem).SaveAsFile Location & "\" & myAttachments.Item(EachItem).DisplayName
    Exit Function'*** Check for mail  
Nout = Locate_Mail(Inbox, "", "Registration_", "")        
Function Locate_Mail(Folder$, From$, Subject$, Body$) As Boolean
    On Error GoTo Locate_Mail_Err        
    Set InboxFolder = theNameSpace.GetDefaultFolder(Folder$)          
    For Each MailItem In InboxFolder.Items
        If InStr(1, MailItem.Subject, Subject$, vbTextCompare) Then
            EachItem = EachItem + 1            x = (InboxFolder.Items.Count)
            'Form1.List1.AddItem "SenderName :" & InboxFolder.Items(EachItem).SenderName
            'Form1.List1.AddItem "ReceivedTime :" & InboxFolder.Items(EachItem).ReceivedTime
            'Form1.List1.AddItem "SentOn :" & InboxFolder.Items(EachItem).SentOn
            'Form1.List1.AddItem "To:" & InboxFolder.Items(EachItem).To
            'Form1.List1.AddItem "Subject : " & InboxFolder.Items(EachItem).Subject
            'Form1.List1.AddItem "UnRead : " & InboxFolder.Items(EachItem).UnRead
            'Form1.List1.AddItem "UnRead : " & InboxFolder.Items(EachItem).Attachment
            'Set myAttachments = InboxFolder.Items(EachItem).Attachments
            'myAttachments.Item(1).SaveAsFile "C:\My Documents\" & myAttachments.Item(1).DisplayName
        End If            Next            If EachItem = 0 Then
        '*** If no mail item found then continue looking
        MAILBOX_STATE = 200        Exit Function    Else
        '*** If mail found set state        MAILBOX_STATE = 250        
    End If            Exit FunctionLocate_Mail_Err:Locate_Mail = False
Exit FunctionEnd Function        Function Outlook_SendMail(Letter As String)
    On Error GoTo Outlook_SendMail_Err    Dim Msg As String    Dim theMailItem
        Select Case Letter        Case "Auto_OneTel"            Msg = "Andrew, "
    Msg = Msg & Chr$(13) & "Confirming receipt of " & InboxFolder.Items(1).Attachments.Item(1).DisplayName
    Msg = Msg & "  received on " & Outlook_Get_Weekday & " " & InboxFolder.Items(EachItem).ReceivedTime & Chr$(13)
    Msg = Msg & "Kind Regards," & Chr$(13)
    Msg = Msg & "OneTel.Services@GlobalOne.net" & Chr$(13)
    Msg = Msg & "<< This is a system generated message >>"    Debug.Print Msg
        Set theMailItem = theApp.CreateItem(olMailItem)    With theMailItem
        .Subject = "Confirmation File- " & InboxFolder.Items(EachItem).Attachments.Item(1).DisplayName
        .Body = Msg        .Recipients.Add "malcolm.wilson@globalone.net"
        .Recipients.Add "wirereg@one.net.au"
        .Recipients.Add "kevinr@one.net.au"        .Send    End With    DoEvents
    Exit Function'*** Move mail to folder
Function MoveMail_To_Folder(Folder As String)
Set mydestfolder = InboxFolder.Folders(Folder)
Set myItem = InboxFolder.Items(EachItem)myItem.Move mydestfolderEnd Function
0
 
LVL 2

Expert Comment

by:cedricd
ID: 1447890
Sorry for the presentation of my reply but i had a little problem
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question