bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
So I have some code that basically does an advance search and checks for the search to be complete and then prints it to the immediate window. Its basically an example modified from microsofts example for using advancesearch function. The error I am tripping is when i set my class application object equal to the one i use in my code:
Set OutlookEventClass.oOutlookApp = OutApp
438 : Object doesn't support this property or method
module code:
class code:
Set OutlookEventClass.oOutlookApp = OutApp
438 : Object doesn't support this property or method
module code:
Code:
'Outlook Variables and Class
Public OutlookEventClass As New OutlookListener
Public Sub SearchOutlook()
'Create Email
'Generate Outlook Email for L&E
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim SearchFolder As Outlook.MAPIFolder
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 0
If OutApp Is Nothing Then
Set OutApp = CreateObject("Outlook.Application")
QuitNewOutlook = True
End If
Set Session = OutApp.GetNamespace("MAPI")
Session.Logon
Set OutlookEventClass.oOutlookApp = OutApp
On Error GoTo OutlookErrors
'We need to ensure outlook is fully connected
ExchangeStatus = Session.ExchangeConnectionMode
If ExchangeStatus <> 700 Then GoTo OutlookErrors
'set scope
Scope = "'" & Application.Session.GetDefaultFolder( _
olFolderInbox).FolderPath _
& "','" & Application.Session.GetDefaultFolder( _
olFolderSentMail).FolderPath & "'"
'Establish filter
If OutApp.Session.DefaultStore.IsInstantSearchEnabled Then
Filter = Chr(34) & "urn:schemas:httpmail:subject" _
& Chr(34) & " ci_phrasematch 'Office'"
Else
Filter = Chr(34) & "urn:schemas:httpmail:subject" _
& Chr(34) & " like '%Office%'"
End If
Set MySearch = OutApp.AdvancedSearch( _
Scope, Filter, True, "MySearch")
While m_SearchComplete <> True
DoEvents
Wend
'Establish filter
If OutApp.Session.DefaultStore.IsInstantSearchEnabled Then
Filter = Chr(34) & "urn:schemas:httpmail:subject" _
& Chr(34) & " ci_phrasematch 'Virginia'"
Else
Filter = Chr(34) & "urn:schemas:httpmail:subject" _
& Chr(34) & " like '%Virginia%'"
End If
Set MySearch = OutApp.AdvancedSearch( _
Scope, Filter, True, "MySearch")
Set MyTable = MySearch.GetTable
Do Until MyTable.EndOfTable
Set nextRow = MyTable.GetNextRow()
Debug.Print nextRow("Subject")
Loop
If QuitNewOutlook Then
OutApp.Quit
End If
Set OutMail = Nothing
Set OutApp = Nothing
'Set ExchangeStatus = Nothing Possible Memory Leak?
Exit Sub
OutlookErrors:
Debug.Print Err.Number & " : " & Err.Description
Set OutMail = Nothing
'Set ExchangeStatus = Nothing Possible Memory Leak?
If Not OutApp Is Nothing And QuitNewOutlook Then
OutApp.Quit
End If
Set OutApp = Nothing
'QueryRunning = False
End Sub
class code:
Code:
Option Explicit
Public WithEvents oOutlookApp As Outlook.Application
Public Sub oOutlookApp_AdvancedSearchComplete(ByVal SearchObject As Search)
If SearchObject.Tag = "MySearch" Then
m_SearchComplete = True
End If
End Sub