how to get Contacts subfolder

J

James

How do I get a 'handle' to a subfolder under the Contacts folder? All
the samples I've seen just refer to getting the default Contact
folder.

I tried the following but it didn't work:

Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("Contacts").Folders("Test")

Thx,

J.
 
H

Hollis D. Paul

James said:
I tried the following but it didn't work:

Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("Contacts").Folders("Test")
You have to walk the folder tree of folders. Remember, that each
folder object contains a folders collection object, as well as an items
collection object. So, if you have:

Set objFolder = objNS.Folders("Contacts")

then you would do the following:

Set objSubContactFolder = objFolder.Folders("Test")

Some would reuse the objFolder object when walking the folder tree, but
I would avoid that on your first run. You can get confused about where
you are if you haven't done twenty times already.

You should also search www.slipstick.com and www.outlookcode.com for
code samples.

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
J

James

Hi Hollis,

Thanks, that worked great!

Another question for you though....it should be simple, but I can't
get it to work. I'm trying to delete all the items in a contacts
folder.

If I try:

For Each Item in objSrcItems
Item.Delete
Next Item

It always leaves the last entry.

If I try:

Do While objSrcItems.Count <> 0
Set Item = objSrcItems.GetFirst
Item.Delete
Loop

It goes off into nowhere land.

Thx,

James
Hollis D. Paul said:
James said:
I tried the following but it didn't work:

Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("Contacts").Folders("Test")
You have to walk the folder tree of folders. Remember, that each
folder object contains a folders collection object, as well as an items
collection object. So, if you have:

Set objFolder = objNS.Folders("Contacts")

then you would do the following:

Set objSubContactFolder = objFolder.Folders("Test")

Some would reuse the objFolder object when walking the folder tree, but
I would avoid that on your first run. You can get confused about where
you are if you haven't done twenty times already.

You should also search www.slipstick.com and www.outlookcode.com for
code samples.

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
H

Hollis D. Paul

James said:
For Each Item in objSrcItems
Item.Delete
Next Item

It always leaves the last entry.
One would think that such a task would be really simple, but the
problem is that every time you delete an item, the list is reset, so
your pointer is off. We used to recommend that you start with the last
entry in the list, and delete from the end, so that you use a count
down cycle.

You first get the count of the list items, which is a property of the
list collection object. You put that static number into the loop
controller, and then delete that member of the list first.

See if that works cleanly/

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
J

James

Thanks Hollis,

That worked! Here's the code I used:

For intCounter = 1 To intItemCount
Set objTmp = objSrcItem.GetLast
objTmp.Delete
Next

J.

Hollis D. Paul said:
James said:
For Each Item in objSrcItems
Item.Delete
Next Item

It always leaves the last entry.
One would think that such a task would be really simple, but the
problem is that every time you delete an item, the list is reset, so
your pointer is off. We used to recommend that you start with the last
entry in the list, and delete from the end, so that you use a count
down cycle.

You first get the count of the list items, which is a property of the
list collection object. You put that static number into the loop
controller, and then delete that member of the list first.

See if that works cleanly/

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 

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