Programmatically get count of view with filter

M

Marvin Bobo

I've created custom views on the contact folder using filters, each view
shows a
group of contacts according to category and filters on user defined fields
in the folder. How can I get a count of who shows up in that filtered view?
I have a .NET Add-In to Outlook 2003 with a custom toolbar button that the
user clicks on, it determines the active view, and then gives a message box
or dialog with the count of the number of items in the custom view. The
count property for the view always return the total number of contacts in the
default contact folder which is the same as what is shown on the status bar
in Outlook.
 
W

Wei-Dong XU [MSFT]

Hi ,

Currently we are researching this issue for you. When we have any idea, we
will update in this thread then.

Have a nice day!

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi,

Now I am researching the issue, and I will update you with new information
ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi,

Based on my researching, what you see in the view is completely different
that what you get in the object library when working with a collection of
items. There is no direct way to return the number of filtered items in a
view, but you could theoretically use the Restrict method in the object
library to perform the same filter, and then the <RestrictedItems>.Count
would return the correct number of items.

Restrict Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/htm
l/olmthRestrict.asp

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi,

Now I am researching the issue to see if there is any method to do the job.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi

Based on my researching, View object has a property of XML which will
define the view and the filter of the view too.
You may try to print out the XML property of the View object and find the
Filter node which contain the information about the filter of the view.
http://groups.google.com/groups?q=filter+"View.XML"+outlook+schema&hl=zh
-CN&lr=&ie=UTF-8&selm=uauCvtPgCHA.1848%40tkmsftngp10&rnum=1

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

The filter used in an XML view is a DASL filter that follows SQL syntax. It
is not usable in a Restrict or Filter clause, which uses different syntax.
However, if you are using Outlook 2002 or 2003, which you have to be using
to work with XML views, you have another option.

Use the AdvancedSearch object, which does use SQL syntax identical to the
syntax used in an XML filter. When the search is complete you receive an
AdvancedSearchComplete event that you can sink. That provides the Search
object that just completed. A Search object has a Results collection that
contains all items that matched your search filter, and it has various Get
methods like GetFirst and GetNext.

You can get the DASL syntax you need for your SQL search by constructing a
filter in the UI in the customize current view dialog. That dialog has a SQL
tab that provides the exact search filter you will need and the DASL
property tag for the Outlook property you are filtering on.
 
P

Peter Huang

Hi

The sink process is similar as below.

Dim WithEvents olApp As Outlook.Application

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
'applicationObject = application
olApp = application
addInInstance = addInInst
TestAdvancedSearchComplete()
End Sub
Public blnSearchComp As Boolean

Sub TestAdvancedSearchComplete()
Dim sch As Outlook.Search
Dim rsts As Outlook.Results
Dim i As Integer
blnSearchComp = False
Const strF As String = "urn:schemas:mailheader:subject = 'abc'"
Const strS As String = "Inbox"
sch = olApp.AdvancedSearch(strS, strF)
While blnSearchComp = False
System.Windows.Forms.Application.DoEvents()
End While
rsts = sch.Results
For i = 1 To rsts.Count
MsgBox(rsts.Item(i).SenderName)
Next
End Sub

Private Sub olApp_AdvancedSearchComplete(ByVal SearchObject As
Microsoft.Office.Interop.Outlook.Search) Handles
olApp.AdvancedSearchComplete
Dim objResults
objResults = SearchObject.Results
MsgBox("AdvancedSearch found : " & objResults.count)
End Sub

How to use the AdvancedSearch method to search for an item in Outlook
http://support.microsoft.com/?kbid=326244

AdvancedSearchComplete Event
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/htm
l/olevtAdvancedSearchComplete.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

Just follow a model similar to the code that Peter Huang posted in this
thread.

Also, make sure to look at the VS.NET information for Outlook development at
http://www.microeye.com/resources/res_outlookvsnet.htm and if you can read
VB 6 and have it installed anywhere take a look at the ItemsCB COM addin
template for some common workarounds for Outlook bugs. For example you
should always test for an Explorer when you instantiate your addin in
On_Connection because On_Disconnection will never fire as long as any
Outlook objects are instantiated. So you have to trap Explorer.Close and
check for the count of Explorers and Inspectors to see when to release your
objects.

Another thing to make sure of is to derive all your Outlook objects from the
Application object passed to you in On_Connection so your addin is trusted
by Outlook 2003 and you don't get the security prompts.

www.outlookcode.com also has lots on Outlook coding, including examples of
AdvancedSearch.
 

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