bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I am trying to pull information from emails i have collected from an advance search. If I use the basic schema names like subject everything works but if i use the schema reference (ie, http://schemas.microsoft.com/mapi/proptag/0x10F4000B) directly it draws an error (5 : Invalid procedure call or argument). See the code below:
Code:
Public Sub SearchOutlook()
'Create Email
'Generate Outlook Email for L&E
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim QuitNewOutlook As Boolean
Dim Session As Outlook.Namespace
Dim ExchangeStatus As OlExchangeConnectionMode
Dim Scope As String
Dim Filter As String
Dim MySearch As Outlook.Search
Dim MyTable As Outlook.Table
Dim nextRow As Outlook.row
m_SearchComplete = False
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
On Error GoTo OutlookErrors
If OutApp Is Nothing Then
Set OutApp = CreateObject("Outlook.Application")
QuitNewOutlook = True
End If
Set Session = OutApp.GetNamespace("MAPI")
Session.Logon
'We need to ensure outlook is fully connected
ExchangeStatus = Session.ExchangeConnectionMode
If ExchangeStatus <> 700 Then GoTo OutlookErrors
Set OutlookEventClass.oOutlookApp = OutApp
'set scope
Scope = "'" & OutApp.Session.Folders("MMCratesetting@cms.hhs.gov").FolderPath & "'"
'Establish filter - DASL schemas below:
'Message ID http://schemas.microsoft.com/mapi/proptag/0x1035001E = <blah.blah@blah.com>
'Subject urn:schemas:httpmail:subject ci_phrasematch 'blah' - Our store uses instant search
'Body urn:schemas:httpmail:textdescription ci_phrasematch 'blah'
'From urn:schemas:httpmail:fromemail
'To urn:schemas:httpmail:to
'cc urn:schemas:httpmail:cc
Dim SubjectsToSearch() As String
SubjectsToSearch = Split("Virginia,Va", ",")
Filter = SubjectSearchSchema(SubjectsToSearch, OutApp.Session.DefaultStore.IsInstantSearchEnabled)
Set MySearch = OutApp.AdvancedSearch(Scope, Filter, True, "MySearch")
'loop until event triggers that search is complete
While m_SearchComplete <> True
DoEvents
Wend
Set MyTable = MySearch.GetTable
Do Until MyTable.EndOfTable
Set nextRow = MyTable.GetNextRow()
Debug.Print nextRow("Subject") & nextRow("http://schemas.microsoft.com/mapi/proptag/0x10F4000B")
Loop
If QuitNewOutlook Then
OutApp.Quit
End If
Set OutMail = Nothing
Set OutApp = Nothing
'Set ExchangeStatus = Nothing Possible Memory Leak?
OutlookErrors:
Set OutMail = Nothing
'Set ExchangeStatus = Nothing Possible Memory Leak?
If Not OutApp Is Nothing And QuitNewOutlook Then
OutApp.Quit
End If
Set OutApp = Nothing
End Sub