Retrive Deleted Email Items from Outlook 2007 and 2010 with VB6

Posted on 2011-05-04
Last Modified: 2012-05-11
NOTE: Chris (craisin) was very helpful in getting me on the right track for the original question that resulted in the code I am listing below.

I have a program that will access MS Outlook from an email address in a text box.  It is working fine in 2010 for the Inbox, Personal Folders, and the Sent Items.  In 2007 it only retrieves data from the Personal Folders.

List below is the code for 2010

 Option Explicit
    '=== For accessing all correspondence for a specifice email address ==================
    Private oOutapp      As outlook.Application
    Private oNs          As outlook.NameSpace
    Private oMyinbox     As outlook.MAPIFolder
    Dim oMyExplorer      As outlook.Explorer

Private Sub SeeEmailInfo_btn_Click()
    If Trim(EMail_txt.Text) = "" Then
        MsgBox "No email address assigned to this customer", vbOKOnly
        Exit Sub
    End If
    Set oOutapp = New outlook.Application
    Set oNs = oOutapp.GetNamespace("MAPI")
    Set oMyinbox = oNs.GetDefaultFolder(olFolderInbox)
    Set oMyExplorer = oMyinbox.GetExplorer
    oMyExplorer.Search EMail_txt.Text, olSearchScopeAllOutlookItems

End Sub

Any ideas on this would be very helpfull

Question by:JackVannoy

    Author Comment

    I have an open question that shows it was posted on 05/04/2011.  The question was a new question, with a new probolem,  that followed up on a question that was resolved and accepted.  the expert who provided the answer for the first queston was Chris (craisin)

    Just curious about the lack of response to this question  I have not receieved and responses as of today 05/09/2011. Guess I want to know what I should do. I think I may have put in the wrong zone.  It should have been either Visual Basic Classic or Prog Language.

    LVL 61

    Accepted Solution


    Including the Outlook and Microsoft Office zones in this question may have been helpful (I have added them, and the Visual Basic zone now).  Even though the programming language you are using is Visual Basic, the commands you are using are very specific to Outlook.  They would be familiar to anyone who does Outlook automation on a regular basis in any programming language, but not necessarily familiar to all Visual Basic programmers -- many of whom have never written Outlook programs.  The combination of VB, Outlook and Office initially would likely have gotten you a quick response.  

    Also, the Request Attention button in the original post will alert the Moderators.  If a question goes for more than 24 hours without comments, you can use this button to ask the Moderators to try to get Experts involved.

    Regarding the actual question, I think your trouble is in this line:

     oMyExplorer.Search EMail_txt.Text, olSearchScopeAllOutlookItems 

    Open in new window

    olSearchScopeAllOutlookItems is a constant available in Outlook 2010, but not in Outlook 2007.  Your code copied as written into Access VBA (Office 2007) caused a compile error.

    You can find search scope constants for Outlook 2010 here:

    The constants for 2007 can be seen by selecting Office 2007 from the 'Other Versions' drop down list at the top of the page.

    Try using olSearchScopeAllFolders  instead:

    oMyExplorer.Search EMail_txt.Text, olSearchScopeAllFolders  

    Open in new window


    Author Comment

    Thank you mbizup for your response and for reminding me of the (Request Attention) button.

    I will give your post a try and respond as to the results.


    Author Closing Comment

    Thank you mbizup,

    The program is working fine now.  I appreciate you giving me the last piece of the puzzle.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
    Use email signature images to promote corporate certifications and industry awards.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now