Solved

Search Top Level Folders in Outlook

Posted on 2002-03-11
6
158 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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