Explanation on weird VB bahaviour W/O a comment

C

crazyv

Hello all,

I have below code in a single Outlook Module. It runs as expected, but only
when i include a line - which does not have any use for within the code!
Which is calling a MsgBox function.

This is probably a very simple explanation which I am not finding for this.

Here is the code:
Sub createMove()
Dim myOlApp As New Application
Dim namespace As namespace
Dim inbFolder As MAPIFolder
Dim myFolder As MAPIFolder
Dim resFolder As MAPIFolder
Dim aa, abc As String
Dim objResult As Results
Dim objSch As Search
Dim item As MailItem

Set namespace = myOlApp.GetNamespace("MAPI")
Set inbFolder = namespace.GetDefaultFolder(olFolderInbox)
Set resFolder = inbFolder.Folders("res")

aa = "urn:schemas:mailheader:subject = 'test'" '& abc
Const strS As String = "'Inbox\test'"
Const strTag As String = "SubjectSearch"
Set objSch = AdvancedSearch(Scope:=strS, Filter:=aa,
SearchSubFolders:=True, Tag:=strTag)

Set objResult = objSch.Results
MsgBox "?" '' IF I DONT HAVE THIS IT WONT GET PAST THIS LINE!
For Each item In objResult
MsgBox "item: " & item.Subject
item.Move resFolder
Next

End Sub
 
C

crazyv

I think this is due to 'advancedsearch' being an asynchronous function and
therefore requires the advancedsearchcomplete event to await the result....
you may correct me if this is wrong ofcourse (?) :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top