Results 1 to 4 of 4
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185

    Close Outlook Filter

    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Does ESC terminate? Is search taking so long need to break off?

    Code would be easier to read and understand if use indentation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185
    Hi June7, yes it is as easy as hitting escape Hmmm should have tried that, reason i ask is, when the filter goes onto the email, we can scroll to find what we need to know then minimize outlook, when we go to grab the next mail, it can't because the filter is still active if this all makes sense.

    We should either get into the routine of hitting escape as suggested or program vb to find instr info we need then maybe see if there is vb that does the same as escape button


  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Only way I know to trigger ESC is with SendKeys command. But don't see how could do that in code to interrupt search.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 09-02-2020, 04:02 PM
  2. How to clear filter when I close out tables?
    By wuzhuo77 in forum Access
    Replies: 5
    Last Post: 07-21-2015, 11:16 AM
  3. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  4. Reset Filter On Close
    By Power in forum Forms
    Replies: 1
    Last Post: 07-26-2011, 02:41 PM
  5. Replies: 2
    Last Post: 06-20-2011, 03:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums