Solved

Segregating mails

Posted on 2004-08-10
5
416 Views
Last Modified: 2010-04-08
Hello Experts,
   I want to segregate mails that have the same date value in mail recieved date and mail sent date With the mails that have different values for these fields into different folders. Can you guide me as to how an I achieve this?
Rgds
Ovais
0
Comment
Question by:MOvais_Khan
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11771197
I think the only way to do this would be to write a MACRO that scan through your folder and compares each items DateValue(ReceivedTime) with the DateValue(SentOn) and if they match then moves them to a different folder.
0
 

Author Comment

by:MOvais_Khan
ID: 11772014
But how to write the macro, I dont have any experience in VB or VBA. Any reference material that I can study and implement this method. Also What will be the method (function) to move the mails to the seperate folder
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11772055
Something like this might work:

Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
0
 

Author Comment

by:MOvais_Khan
ID: 11772522
gives me debug error on the line
     If DateValue(oMessage.ReceivedTime) = DateValue(oMessage.SentOn) Then

Just Curious, Is this VBA, Can i have some study and reference material for VBA, as i have a lot of customizations that i think i can achieve with programming, so its better I learn about it
0
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 250 total points
ID: 11845056
Oops, I just realised I never got back to you on this. Sorry. Try assigning the dates to variables and then comparing them in the if statement like this:
****************************
Sub MoveMail()
   
    'Declare Objects & Variables
    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFromFldr As Outlook.MAPIFolder
    Dim oToFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim oMBox As String
    Dim inDate As Date, outDate As Date
   
    'Setup the object variables
    Set oOutlook = New Outlook.Application
    Set oNs = oOutlook.GetNamespace("MAPI")
    oMBox = MsgBox("First select the folder FROM which to get your mail:", vbOKOnly)
    Set oFromFldr = oNs.PickFolder
    oMBox = MsgBox("Now select the folder to move the messages to:", vbOKOnly)
    Set oToFldr = oNs.PickFolder

    'Move all mailitems from origin to destination folders if Rec'd Date and Sent Date are the same
    For Each oMessage In oFromFldr.Items
        inDate = DateValue(oMessage.ReceivedTime)
        outDate = DateValue(oMessage.SentOn)
        If inDate = outDate Then
            oMessage.Move oToFldr
        End If
    Next oMessage
   
    'Clean up object variables
    Set oOutlook = Nothing
    Set oNs = Nothing
    Set oFromFldr = Nothing
    Set oToFldr = Nothing
   
End Sub
****************************

And yes this is VBA. I don't really know what to reccomend as far as study material. There are books available, but I personnaly have a hard time learning from books and prefer to learn by studying other peoples examples. There is a cool website that you might find useful:

http://www.outlookcode.com/code2.aspx?level=b


This book looks good:

http://www.pearsoned.co.uk/bookshop/detail.asp?item=100000000055448&affid=tre
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now