Troubleshooting Outlook 2010 AdvancedSearch method

Mark Dalley
Mark Dalley used Ask the Experts™
on
Hello Experts

I am searching for emails in Outlook 2010 from Access 2010 VBA and want to use the AdvancedSearch method.
I know that the email I am searching for exists because I can see it in the Deleted Items folder. However, after at least 30 minutes of searching, AdvancedSearch hasn’t yet found it. The AdvancedSearchComplete event hasn’t yet fired (or if it has I haven’t detected it) and the search result set is empty. After this time, I find it hard to believe that sheer slowness is the problem.
Some more details:

1.      All the action is occurring in the Access class module for my email management form. In the form’s module header, I declare a WithEvents reference to my desktop Outlook instance, which I check is up and running, along with some related stuff:
Private WithEvents molApp As Outlook.Application      ‘ in class module header
Private mblnIsSearchComplete As Boolean   ' set True when email search completes

Private molNS As Outlook.NameSpace
Private molFldrBase As Outlook.Folder
Private WithEvents molFldrInbox As Outlook.Folder
Private WithEvents molFldrDeleted As Outlook.Folder
Private WithEvents molInboxItems As Outlook.Items


2.      In the Form_Open event handler, I set up the necessary references, first to Outlook, which I check is up and running, and then to key email folders:
  Set molApp = GetObject(, "Outlook.Application")  ' will raise error if not already running
   mblnIsSearchComplete = False


   Set molNS = molApp.GetNamespace("MAPI")
   Set molFldrBase = GetOutlookBaseFolder(molNS)  ' instantiate base folder using value(s) in Control table
   Set molFldrInbox = molFldrBase.folders("Inbox")
   Set molFldrDeleted = molFldrBase.folders("Deleted Items")
   Set molInboxItems = molFldrInbox.Items

3.      I have an event handler for the AdvancedSearchComplete event:
Private Sub molApp_AdvancedSearchComplete(ByVal SearchObject As Outlook.Search)
   If SearchObject.Tag = "LostSearch" Then mblnIsSearchComplete = True
End Sub


4.      I am searching on the BIllingInformation field of the email, which for the email in question contains the text “Deleted;4256” without the quotes.

5.      The search parameters are (checked via the immediate window):
a.      strFltr has the value  "urn:schemas:contacts:billinginformation" LIKE '%4256%'
Note that the value actually contains the single and double quotes shown. Adding enclosing quotes would only confuse things.
b.      strScope has the value '\\myfirstname.mylastname@nhs.net\Deleted Items'
Again, the single quotes are literally present and not just setting off a string value

6.      The actual search which doesn’t seem to want to terminate is kicked off by
   Set molSearch = Outlook.AdvancedSearch(strScope, strFltr, False, "LostSearch")

Any ideas what could be wrong? I’d be interested to hear if anyone else has used the Outlook AdvancedSearch method successfully from Access.

Yours hopefully

Kiwi_731
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kyle SantosSoftware Test Analyst I at Dassault Systemes

Commented:
Hi,

I am following up on your question.  Do you still need help?

If you solved the problem on your own, would you please post the solution here in case others have the same problem?

Regards,

Kyle Santos
Customer Relations
Mark DalleyInformation Analyst

Author

Commented:
Hi Everyone

I have not found any way of making advanced search faster, and I suspect there isn't one.

I did find a class module ( christened "FastSearch" by its author) which was supposed to help someone else solve a similar problem to the one I am having. When I examined the code, however the way it works was bascally the same as mine, and its speed - at least on the email system I use at work, which is where I need it to work - was equally abysmal.

I would of course be very happy to be proved wrong.

At present, I am finding that it is faster to search the relevant properties directly with VBA rather than entrust it to the AdvancedSearch method.

Kiwi_731
Kyle SantosSoftware Test Analyst I at Dassault Systemes

Commented:
Hi,

Thank you for letting me know.  Would you want me to send more alerts out to experts to see if they can assist you with this problem?  Or would you like to delete or just leave it open for now?
Mark DalleyInformation Analyst

Author

Commented:
Please feel free to send out more alerts.

I feel that the main thing lacking is input from someone who can say of AdvancedSearch: This is its overall design, hence best way to use it is X, bearing in mind that it doesn't play well with Y because of Z...

If someone like Sue Mosher or Dmitry Streblechenko could weigh in, that would be just awesome...

Yours hopefully

Kiwi_731

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial