Clear a view Filter in code.

J

Joe Bonifazi

I asked this question twice before with no responses. :(

Here is the "solution" I finally came up with, but it still leaves one
undesired effect.


Problem:
I use the "Filter" function a lot! In each of my folders, the filter
remains in effect until I open the filter dialog box again, select "Clear
All" and "OK" buttons. That's 3 clicks, too many for me. Yes - I really am
that lazy.

Further problem:
I wrote some code - using information I gathered in this forum - Thank you.
I used MSXML2 .DOMDocument30, loaded the XML from the current view ( with
the filter set ) and then set the filter string to NULL. This did NOT clear
the filter every time. Which made it a worse problem - because it did work
some of the time.

Current Status:
I not set the filter to "0" - it really doesn't matter too much - I could
set it to one. Now all mail items are shown ( un-filterd) but in the top
right corner of my view it still says "(Filter Applied)".

When I open the filter dialog window, I get the SQL tab with a "0" in it,
which is not a valid statement, so I must clear it.



How can I correctly clear the filter on the view?
My suspicion is that I must delete the XML Filter token all together, and
not just set it to NULL or "0" -- How can I do this?


ANY reply would be appreciated.
 
J

Joe Bonifazi

Sorry - forgot to post my code. Also I have a Typo above - under Current
status I meant to say: I now set the filter ....


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

objView.LockUserChanges = False 'Allow changes to the
view


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

strElement = "view/filter" '* ??? MAYBE I NEED TO DELETE THIS
ELEMENT ???

Set objNode = objXMLDOM.selectSingleNode(strElement)

'objNode.nodeTypedValue = "urn:schemas:httpmail:datereceived >=
'1/7/1950'" '* One example to show all items
objNode.nodeTypedValue = 0 '* Shows all Items but
still says (Filter Applied)


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

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