PC Review


Reply
Thread Tools Rate Thread

Accessing outlook contacts

 
 
John
Guest
Posts: n/a
 
      11th Mar 2005
Hi

I am trying to access outlook contacts folders and delete the contacts that
do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards


Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      12th Mar 2005
Hi,

Here is a sample console app.

Imports System.Reflection

Imports Outlook = Microsoft.Office.Interop.Outlook

Module Module1

Sub Main()

' Create Outlook application.

Dim oApp As Outlook.Application = New Outlook.Application

' Get Mapi NameSpace.

Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")

oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:

' Get Messages collection of Inbox.

Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

Dim oItems As Outlook.Items = oInbox.Items

Console.WriteLine("Total : " & oItems.Count)

Console.WriteLine("Total Unread : " & oItems.Count)

' Loop each unread message.

Dim oContact As Outlook.ContactItem

Dim i As Integer

For i = 1 To oItems.Count

Try

oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)

Console.WriteLine(i)

Console.WriteLine(oContact.FullName)

Catch

End Try

Console.WriteLine("---------------------------")

Next

' Log off.

oNS.Logoff()

' Clean up.

oApp = Nothing

oNS = Nothing

oItems = Nothing

oContact = Nothing

End Sub

End Module



Ken

-------------------

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi

I am trying to access outlook contacts folders and delete the contacts that
do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards


Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      12th Mar 2005
Hi

I am getting a "Namespace or type 'Outlook' for the Imports
'Microsoft.Office.Interop.Outlook' cannot be found." error on line Imports
Outlook = Microsoft.Office.Interop.Outlook. Any idea what I am doing wrong?

Thanks

Regards


"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Here is a sample console app.
>
> Imports System.Reflection
>
> Imports Outlook = Microsoft.Office.Interop.Outlook
>
> Module Module1
>
> Sub Main()
>
> ' Create Outlook application.
>
> Dim oApp As Outlook.Application = New Outlook.Application
>
> ' Get Mapi NameSpace.
>
> Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
>
> oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:
>
> ' Get Messages collection of Inbox.
>
> Dim oInbox As Outlook.MAPIFolder =
> oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
>
> Dim oItems As Outlook.Items = oInbox.Items
>
> Console.WriteLine("Total : " & oItems.Count)
>
> Console.WriteLine("Total Unread : " & oItems.Count)
>
> ' Loop each unread message.
>
> Dim oContact As Outlook.ContactItem
>
> Dim i As Integer
>
> For i = 1 To oItems.Count
>
> Try
>
> oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)
>
> Console.WriteLine(i)
>
> Console.WriteLine(oContact.FullName)
>
> Catch
>
> End Try
>
> Console.WriteLine("---------------------------")
>
> Next
>
> ' Log off.
>
> oNS.Logoff()
>
> ' Clean up.
>
> oApp = Nothing
>
> oNS = Nothing
>
> oItems = Nothing
>
> oContact = Nothing
>
> End Sub
>
> End Module
>
>
>
> Ken
>
> -------------------
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> Hi
>
> I am trying to access outlook contacts folders and delete the contacts

that
> do not contain a certain category value in the categories field. I have
> written the below code but am stuck with the error on the indicated line.
> Any help would be appreciated.
>
> Thanks
>
> Regards
>
>
> Dim O As Outlook.Application
> Dim F As Outlook.MAPIFolder
> Dim ICount As Long
> Dim oContact As Outlook.ContactItem
> Dim obj As Outlook.ContactItem
>
> O = New Outlook.Application
> F =

O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
> For Each obj In F.Items() ' This line gives error: Expression is of type
> 'Outlook.Items', which is not a collection type.
> If TypeOf obj Is Outlook.ContactItem Then
> oContact = obj
> If InStr(oContact.Categories, "mycat") Then
> oContact.Delete()
> End If
> End If
> Next
>
>
>



 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      13th Mar 2005
Hi,

I would recomend using the office interop assemblies they solve some
problems with working with office. If you are not using them you can get
rid of that imports statement.

http://msdn.microsoft.com/library/de...embliesFAQ.asp

Ken
--------------------------------
"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi

I am getting a "Namespace or type 'Outlook' for the Imports
'Microsoft.Office.Interop.Outlook' cannot be found." error on line Imports
Outlook = Microsoft.Office.Interop.Outlook. Any idea what I am doing wrong?

Thanks

Regards


"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Here is a sample console app.
>
> Imports System.Reflection
>
> Imports Outlook = Microsoft.Office.Interop.Outlook
>
> Module Module1
>
> Sub Main()
>
> ' Create Outlook application.
>
> Dim oApp As Outlook.Application = New Outlook.Application
>
> ' Get Mapi NameSpace.
>
> Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
>
> oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:
>
> ' Get Messages collection of Inbox.
>
> Dim oInbox As Outlook.MAPIFolder =
> oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
>
> Dim oItems As Outlook.Items = oInbox.Items
>
> Console.WriteLine("Total : " & oItems.Count)
>
> Console.WriteLine("Total Unread : " & oItems.Count)
>
> ' Loop each unread message.
>
> Dim oContact As Outlook.ContactItem
>
> Dim i As Integer
>
> For i = 1 To oItems.Count
>
> Try
>
> oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)
>
> Console.WriteLine(i)
>
> Console.WriteLine(oContact.FullName)
>
> Catch
>
> End Try
>
> Console.WriteLine("---------------------------")
>
> Next
>
> ' Log off.
>
> oNS.Logoff()
>
> ' Clean up.
>
> oApp = Nothing
>
> oNS = Nothing
>
> oItems = Nothing
>
> oContact = Nothing
>
> End Sub
>
> End Module
>
>
>
> Ken
>
> -------------------
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> Hi
>
> I am trying to access outlook contacts folders and delete the contacts

that
> do not contain a certain category value in the categories field. I have
> written the below code but am stuck with the error on the indicated line.
> Any help would be appreciated.
>
> Thanks
>
> Regards
>
>
> Dim O As Outlook.Application
> Dim F As Outlook.MAPIFolder
> Dim ICount As Long
> Dim oContact As Outlook.ContactItem
> Dim obj As Outlook.ContactItem
>
> O = New Outlook.Application
> F =

O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
> For Each obj In F.Items() ' This line gives error: Expression is of type
> 'Outlook.Items', which is not a collection type.
> If TypeOf obj Is Outlook.ContactItem Then
> oContact = obj
> If InStr(oContact.Categories, "mycat") Then
> oContact.Delete()
> End If
> End If
> Next
>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Vista Windows Contacts and Outlook Contacts using c# mrabie Microsoft C# .NET 0 6th Feb 2008 10:53 AM
Accessing Outlook Contacts SWu Microsoft ASP .NET 1 28th Jun 2004 01:17 PM
Accessing Outlook contacts... J S Microsoft Outlook VBA Programming 1 16th Apr 2004 06:29 PM
Accessing Outlook contacts... J S Microsoft Outlook Form Programming 1 16th Apr 2004 06:29 PM
accessing Outlook contacts using ADO tmaster Microsoft Outlook VBA Programming 1 24th Dec 2003 06:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 PM.