Programmed Custom View

D

Darryl

Custom View
I have written some code to build a search based on custom fields in a form. I built a view including filtering on each of the custom fields on which I want to search. This code takes the XML language from that search, and uses teh replace function to change the search to what the user inputs. This is working great except for one thing - it only works the first time I use it. If I use it a second time in the same Outlook session, the filter does not change even though the code deletes the old view and recreates it. It works fine if I close and re-open Outlook.

The code follows - any suggestions

Sub SearchView(
' Code to build custom search view looking in specified fields inclusing custom field
' Written by Darryl Hendricks, Systems Engineering 4/29/0

' NOTE: All view names are case senstitiv
' Need to build initial view first!! Called zSearc
' Declare all variable
Dim olApp As Outlook.Applicatio
Dim objName As Outlook.NameSpac
Dim objViews As Outlook.View
Dim objView As Outlook.Vie
Dim strOldString As String ' xml view from zSearc
Dim strText As String 'Variable for "test" used in zSearc
Dim strNewString As String ' xml view after replacing text with inpu
Dim strFolder As String ' Folder name for public folder - client matte
Dim strInput As String ' Prompt user for search strin
Dim objFolder As MAPIFolde

Set olApp = Outlook.Applicatio
Set objName = olApp.GetNamespace("MAPI"

' Set focus to client matter folder and grab view
strFolder = "client matters

Set objViews = objName.Folders("Public Folders").
Folders("All Public Folders").Folders(strFolder).View

' Prompt user for input strin
strInput = InputBox("Enter text to search", "Client Matters Custom Search"

' Set view to zSearch to get basic xml cod
Set objView = objViews.Item("zSearch"
objView.Appl
' Remove old "found" view so we can recreate i
objViews.Remove ("Found") ' cASE sENSITIV

' Replace "test" for from zSearch with inputted text in the XML cod
strText = "test" ' This is the text in the zSearch vie
strOldString = objView.XM
strNewString = Replace(strOldString, strText, strInput

' Replace AND with OR statements in the filter strin
strNewString = Replace(strNewString, "AND", "OR"

' Set view to new XML code with Search string in i
Set objView = objViews.Add(Name:="Found", ViewType:=olCardView
objView.XML = strNewStrin
Set objView = objViews.Item("Found"
objView.Apply ' Apply the newly created vie

' Clean u
Set olApp = Nothin
Set objName = Nothin
Set objViews = Nothin
Set objView = Nothin

End Sub
 

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