expression which is not collaction type error in vb.net

S

Sanjay

hi to all

i have code for getting contact folders from outlook. but when i was
colllect all folders name in one variable and then getting for which is
contact folder i use FOR EACH loop. that time it is giving error saying
that that varible is not collection type

i type my code here

Dim oFolder As Outlook.MAPIFolder
Dim colFolders As Outlook.Folders

On Error Resume Next

colFolders = oSourceFolder.Folders
If Not (colFolders Is Nothing) Then

For Each oFolder In colFolders
If colFolders.DefaultItemType = olContactItem Then
'do whatever
End If
'recursive call to SetAllContactFolders.
'repeat until no more subfolders
Call SetAllContactFolders(oFolder)
Next
End If

oFolder = Nothing
colFolders = Nothing

it is giving error at FOR EACH oFolder in ColFolders . so error at
ColFolders.

ok so what's prob is.

thanks
 
K

Ken Slovak - [MVP - Outlook]

See if it works if you change this line:

If colFolders.DefaultItemType = olContactItem Then

to this:

If oFolder.DefaultItemType = olContactItem Then
 
S

Sanjay

Hi ken

Thanks for reply. Now I have problem with this line not which u have
said.

For Each oFolder In colFolders

In this line it is giving error that "colFolders is not a collection
type". so what i have to use or which type i have to declare for that
solving error.
 
K

Ken Slovak - [MVP - Outlook]

Maybe there are no subfolders? Try testing for oSourceFolder.Folders.Count.

Folders is definitely a collection object.
 

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