Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Search Top Level Folders in Outlook

Posted on 2002-03-11
6
Medium Priority
?
167 Views
Last Modified: 2010-05-02
I am using the Microsoft Outlook 10.0 object  library to access Outlook. For some reason I am able to use the Folder.Find method on any sub-folder and provided there is mail that meets the search criteria, this mail is returned by the method and can be manipulated.

If I initialise a folder object to the Inbox, and attempt to use the .Find method, I never get a result. Does the .Find method work on the Inbox? Is there something particular to the Inbox that needs to be done in order for .Find to work?

My code looks similar to what follows:

set fldInbox = NS.GetDefaultFolder(olFolderInbox)
set MSG = fldInbox.Items.Find(sCriteria)

       '''  OR

set MSG = fldInbox.Find(sCriteria)

MSG.Display    '''err is Object Variable not set '91'

Thanks All.
0
Comment
Question by:RobDillon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 39

Expert Comment

by:abel
ID: 6856122
Hmm, I wonder. I use library version 9.0 and the following code to search the inbox:

    Dim app As Outlook.Application
    Dim ns As NameSpace
    Set app = GetObject(, "Outlook.Application")
    Set ns = app.GetNamespace("MAPI")
   
    Dim fld As MAPIFolder, itm As MailItem
    Set fld = ns.GetDefaultFolder(olFolderInbox)
    Set itm = fld.Items.Find("[From] = ""Experts Exchange""")
   
    Debug.Print itm.Subject


You may want to cut and paste it and compare it to your code or temporarily replace it to see if my code works at your machine.

Note that the message "Object variable or With block variable not set" (91) means that the search executed without an error, but did not have any results. The above one works for my inbox because I do have mail from Experts Exchange (and you probable have some too).

Btw, maybe you rather use CreateObject instead of GetObject, but that choice you've probably already made.

If this all doesn't help, please give a full dump of your code, maybe there's something missing, or maybe you simply overlook some tiny detail.

Regards,
Abel
0
 

Author Comment

by:RobDillon
ID: 6856353
Thanx Abel,

Since posting I've realised there is an issue omitted from my question (Apologies). The message field I wish to search by is a user property. This does not explain why my searches work on the subfolders but not on the Inbox?

I have added a column in all my outlook folders for the user property in question. The only messages that are found by the .Find method called on the inbox are 2 messages whose forms I edited to have a text box bound to my user property. If necessary I can replace my user's default mail forms on installation but I feel this is probably not necessary since I am able to search by the user property without doing this where the sub folders are concerned.

Outlook gurus?
0
 
LVL 39

Expert Comment

by:abel
ID: 6862063
Maybe you should place a reference to this question in the MS Outlook area. Or delete this q. and repost it there.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:RobDillon
ID: 6863856
Thanx Abel,
I will take your advice, but against my better judgement and all the rules of ettiquette I will commit the ultimate sin and .... Double Post!
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7618208
Hi RobDillon,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

RobDillon, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 7665584
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

704 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