How to count filtered Elements

M

Martin

Hi,

i have defined a view with a filter and i want to know how many contact
items are remaining after applying my filter/view.

can i use the count propertie?

Thanks for advices ore code snippets.

Martini
 
D

Dmitry Streblechenko \(MVP\)

Restrict the folder items using the same restriction and see how many items
you will get, then subtract that number from the total # of items in the
folder
set RestrItems = MAPIFolder.Items.Restrict(...)
MsgBox MAPIFolder.Items.Count-RestrItems.Count

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

Martin

Dmitry,

my restriction was not realized with vba, i did it "manual". nevertheless i
realized it with vba and now i have a problem with the restriction Method an
user defined fields. I get a massage "field unknown".

any hint?
 
M

Martin

this is my code:

Sub CountItem()
'Zählt alle markierten Elemente und gibt die Anzahl in einer Messagebox aus

Dim myOlApp, myContacts, folContact, myNameSpace

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set folContact = myNameSpace.Folders("Öffentliche Ordner").Folders("Alle
Öffentlichen Ordner").Folders("Kontakte")
Set myContacts = myNameSpace.GetDefaultFolder(olFolderContacts).Items

Set myRestrictItems = myContacts.Restrict("[userfield]<>''")

MsgBox myRestrictItems.Count


Set myOlApp = Nothing
Set myContacts = Nothing
Set folContact = Nothing
Set myNameSpace = Nothing
End Sub

userfield is a user defined variable.

any clue?
 
D

Dmitry Streblechenko \(MVP\)

But how userfield was added to the list of the custom properties in the
folder?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Martin said:
this is my code:

Sub CountItem()
'Zählt alle markierten Elemente und gibt die Anzahl in einer Messagebox aus

Dim myOlApp, myContacts, folContact, myNameSpace

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set folContact = myNameSpace.Folders("Öffentliche Ordner").Folders("Alle
Öffentlichen Ordner").Folders("Kontakte")
Set myContacts = myNameSpace.GetDefaultFolder(olFolderContacts).Items

Set myRestrictItems = myContacts.Restrict("[userfield]<>''")

MsgBox myRestrictItems.Count


Set myOlApp = Nothing
Set myContacts = Nothing
Set folContact = Nothing
Set myNameSpace = Nothing
End Sub

userfield is a user defined variable.

any clue?


Dmitry Streblechenko (MVP) said:
What is your code? How did you add a user property?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


nevertheless Method
 
M

Martin

Dmitry,

i've got it, the codeline Set myContacts =
myNameSpace.GetDefaultFolder(olFolderContacts).Items was not right, it must
be Set myContacts = folContact.Items

thx


Dmitry Streblechenko (MVP) said:
But how userfield was added to the list of the custom properties in the
folder?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Martin said:
this is my code:

Sub CountItem()
'Zählt alle markierten Elemente und gibt die Anzahl in einer Messagebox aus

Dim myOlApp, myContacts, folContact, myNameSpace

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set folContact = myNameSpace.Folders("Öffentliche Ordner").Folders("Alle
Öffentlichen Ordner").Folders("Kontakte")
Set myContacts = myNameSpace.GetDefaultFolder(olFolderContacts).Items

Set myRestrictItems = myContacts.Restrict("[userfield]<>''")

MsgBox myRestrictItems.Count


Set myOlApp = Nothing
Set myContacts = Nothing
Set folContact = Nothing
Set myNameSpace = Nothing
End Sub

userfield is a user defined variable.

any clue?


Dmitry Streblechenko (MVP) said:
What is your code? How did you add a user property?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Dmitry,

my restriction was not realized with vba, i did it "manual". nevertheless
i
realized it with vba and now i have a problem with the restriction Method
an
user defined fields. I get a massage "field unknown".

any hint?





Restrict the folder items using the same restriction and see how many
items
you will get, then subtract that number from the total # of items
in
the
folder
set RestrItems = MAPIFolder.Items.Restrict(...)
MsgBox MAPIFolder.Items.Count-RestrItems.Count

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Hi,

i have defined a view with a filter and i want to know how many
contact
items are remaining after applying my filter/view.

can i use the count propertie?

Thanks for advices ore code snippets.

Martini
 
Top