Programatically clearing a persistent filter

J

Joe Bonifazi

First: This is my first post here - forgive me if I violate some conventions.
I have performed several searches on this topic and did not come up with the
answer I was looking for.

Let me clarify what I mean by my subject:
I love to use the Filter dialog on my views, so much that I have added a
button to my command bar to open the filter dialog window. It bothered me
that to Clear the filter I had to open the dialog box again, Click "Clear
All", and Click OK ( Yes I am that lazy - why do 3 clicks when I should be
able to do one.

I investigated the view obect and found how to use MSXML2 to modify the
filter node to clear the filter. Horray - now I have a one click button on
my command bar to clear the filter.

BUT - I have found one problem, what I am calling a persistent filter. If I
apply a filter to a folder (Inbox), browse another another folder ( Drafts )
and then return to my Inbox, the filter is still applied. If I now run my
macro, it does not clear the filter ??? If i manually clear it with the 3
buttons mentions above, and then run my ClearViewFilter macro, the original
filter is re-appied???

WHAT IS GOING ON?? How do I correct for it??

Here is my macro:
Code:
Sub ClearViewFilter()


Dim objOutlook As Outlook.Application
Dim objActExpl As Outlook.Explorer
Dim olfolder As Outlook.MAPIFolder

Dim objView As Outlook.View
Dim colViews As Outlook.Views
Dim objXMLDOM As New MSXML2.DOMDocument30
Dim objNode As MSXML2.IXMLDOMNode

Set objOutlook = CreateObject("Outlook.Application")
Set objActExpl = objOutlook.ActiveExplorer
Set colViews = objActExpl.CurrentFolder.Views
Set olfolder = objActExpl.CurrentFolder
Set objView = olfolder.CurrentView


'Load the XML for the new view into XML DOM object
objXMLDOM.loadXML (objView.XML)

strElement = "view/filter"
'MsgBox objXMLDOM.nodeName

Set objNode = objXMLDOM.selectSingleNode(strElement)
Debug.Print objNode.Text
objNode.nodeTypedValue = ""                 ' Clear the existing filter
Debug.Print objNode.Text

objView.XML = objXMLDOM.XML                     'Assign the XML for View
to objXML.XML

objView.Save                                    'Save the View
objView.Apply                                   'Apply the View in the
folder

Debug.Print objView.XML


End Sub
[\code]


I am running Outlook 2003 ( 11.6401.6408 ) SP1
 

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