Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search Top Level Folders in Outlook

Posted on 2002-03-11
6
Medium Priority
?
172 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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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