Hi Guy's hope everyone is safe and well
I have this code that will search history of an email address, all works great, just to give it a finishing touch, when the email address goes into outlook search, is there a method in vba to terminate the search and clear the searchstring ?
Code:
Dim fName() As String, SName() As String, BookMail() As String, BookTitle() As String
myTitle As String, myfName As String, mySName As String, MailBody As String, SearchString As String
Dim c As Integer, d As Integer, e As Integer, f As Integer
Dim app As Outlook.Application
If Me.cboMailHistory = "Booking" Then
BookTitle = Split(MailBody, vbCrLf)
For c = 0 To UBound(BookTitle)
If InStr(1, BookTitle(c), "Title:") > 0 Then
myTitle = Mid(BookTitle(c), 7)
End If
Next c
CopyfName = Split(MailBody, vbCrLf)
For d = 0 To UBound(CopyfName)
If InStr(1, CopyfName(d), "Forename:") > 0 Then
myfName = Mid(CopyfName(d), 10)
End If
Next d
CopysName = Split(MailBody, vbCrLf)
For e = 0 To UBound(CopysName)
If InStr(1, CopysName(e), "Surname:") > 0 Then
mySName = Mid(CopysName(e), 9)
End If
Next e
BookMail = Split(MailBody, vbCrLf)
For f = 0 To UBound(BookMail)
If InStr(1, BookMail(f), "Email Address:") > 0 Then
Me.txtEmailAddress = Mid(BookMail(f), 15)
End If
Next f
End If
SearchString = Replace(Me.txtEmailAddress, " " & Me.txtEmailAddress, "" & Me.txtEmailAddress)
Set app = GetObject(, "Outlook.Application")
On Error GoTo 0
If app Is Nothing Then
Set app = CreateObject("Outlook.Application")
app.Explorers.Add app.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
app.Explorers(1).Activate
End If
app.ActiveExplorer.Search SearchString, olSearchScopeAllFolders
Set app = Nothing
DoCmd.RunCommand acCmdAppMinimize