Solved

Search Top Level Folders in Outlook

Posted on 2002-03-11
6
151 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

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

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

22 Experts available now in Live!

Get 1:1 Help Now