![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I'm new to Outlook vb porgramming, and have a simple question
In the code below, I am attempting to list the distribution lists in my personal contacts folder. The first example does the initial loop, but will not continue. Why? I would prefer to not have to iterate over every single contact if possible in order to speed things up. (My eventual goal is to loop thru my contacts, and match them up with what dl's they are in. Do I need to do the same loop inside itself to do this? Probably best for a seperate post...) '--- Start Example --- Dim obj As Object Dim oDistList As Outlook.DistListItem Dim oContact As Outlook.ContactItem Dim oItems As Outlook.Items Set oItems = Application.GetNamespace("mapi").GetDefaultFolder( olFolderContacts).Items ' Obtain List of DL's ''--- Would prefer this method as it seems it would be a faster way For Each oDistList In oItems Debug.Print oDistList.DLName, oDistList.MemberCount '--- Runtime Error '13' at this line (Next) Next '---This loop works fine For Each obj In oItems If TypeOf obj Is Outlook.DistListItem Then Set oDistList = obj Debug.Print oDistList.DLName, oDistList.MemberCount End If Next |
Ads |
#2
|
|||
|
|||
![]()
The loop is failing because it's hitting an item that's a contact and not a
DL. If you want to iterate only DL's then get the Items collection of the folder and set a Restrict clause on it to filter only items with the MessageClass for a DL. That way the restricted Items collection you get returned to you will only have DL's in it. See the Object Browser help on Restrict for examples of how to set up a restriction. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Zarqy" wrote in message ups.com... I'm new to Outlook vb porgramming, and have a simple question In the code below, I am attempting to list the distribution lists in my personal contacts folder. The first example does the initial loop, but will not continue. Why? I would prefer to not have to iterate over every single contact if possible in order to speed things up. (My eventual goal is to loop thru my contacts, and match them up with what dl's they are in. Do I need to do the same loop inside itself to do this? Probably best for a seperate post...) '--- Start Example --- Dim obj As Object Dim oDistList As Outlook.DistListItem Dim oContact As Outlook.ContactItem Dim oItems As Outlook.Items Set oItems = Application.GetNamespace("mapi").GetDefaultFolder( olFolderContacts).Items ' Obtain List of DL's ''--- Would prefer this method as it seems it would be a faster way For Each oDistList In oItems Debug.Print oDistList.DLName, oDistList.MemberCount '--- Runtime Error '13' at this line (Next) Next '---This loop works fine For Each obj In oItems If TypeOf obj Is Outlook.DistListItem Then Set oDistList = obj Debug.Print oDistList.DLName, oDistList.MemberCount End If Next |
#3
|
|||
|
|||
![]()
Ken,
the Restrict look simple enough, but I am lost with the "MessageClass for a DL" part. in my example would I still use the oDistList? For Each oDistList.Restrict("[???] = 'DistListItem' ") in oItems ... Is this even close? I'm sure once I see this in action it will make sense, but right now it is as clear as muddy water. I see something, but not sure its the right thing. Ken Slovak - [MVP - Outlook] wrote: The loop is failing because it's hitting an item that's a contact and not a DL. If you want to iterate only DL's then get the Items collection of the folder and set a Restrict clause on it to filter only items with the MessageClass for a DL. That way the restricted Items collection you get returned to you will only have DL's in it. See the Object Browser help on Restrict for examples of how to set up a restriction. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Zarqy" wrote in message ups.com... I'm new to Outlook vb porgramming, and have a simple question In the code below, I am attempting to list the distribution lists in my personal contacts folder. The first example does the initial loop, but will not continue. Why? I would prefer to not have to iterate over every single contact if possible in order to speed things up. (My eventual goal is to loop thru my contacts, and match them up with what dl's they are in. Do I need to do the same loop inside itself to do this? Probably best for a seperate post...) '--- Start Example --- Dim obj As Object Dim oDistList As Outlook.DistListItem Dim oContact As Outlook.ContactItem Dim oItems As Outlook.Items Set oItems = Application.GetNamespace("mapi").GetDefaultFolder( olFolderContacts).Items ' Obtain List of DL's ''--- Would prefer this method as it seems it would be a faster way For Each oDistList In oItems Debug.Print oDistList.DLName, oDistList.MemberCount '--- Runtime Error '13' at this line (Next) Next '---This loop works fine For Each obj In oItems If TypeOf obj Is Outlook.DistListItem Then Set oDistList = obj Debug.Print oDistList.DLName, oDistList.MemberCount End If Next |
#4
|
|||
|
|||
![]()
Also,
doesn't the Dim oDistList As Outlook.DistListItem .... For Each oDistList In oItems already act as a filter? Zarqy wrote: Ken, the Restrict look simple enough, but I am lost with the "MessageClass for a DL" part. in my example would I still use the oDistList? For Each oDistList.Restrict("[???] = 'DistListItem' ") in oItems ... Is this even close? I'm sure once I see this in action it will make sense, but right now it is as clear as muddy water. I see something, but not sure its the right thing. Ken Slovak - [MVP - Outlook] wrote: The loop is failing because it's hitting an item that's a contact and not a DL. If you want to iterate only DL's then get the Items collection of the folder and set a Restrict clause on it to filter only items with the MessageClass for a DL. That way the restricted Items collection you get returned to you will only have DL's in it. See the Object Browser help on Restrict for examples of how to set up a restriction. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Zarqy" wrote in message ups.com... I'm new to Outlook vb porgramming, and have a simple question In the code below, I am attempting to list the distribution lists in my personal contacts folder. The first example does the initial loop, but will not continue. Why? I would prefer to not have to iterate over every single contact if possible in order to speed things up. (My eventual goal is to loop thru my contacts, and match them up with what dl's they are in. Do I need to do the same loop inside itself to do this? Probably best for a seperate post...) '--- Start Example --- Dim obj As Object Dim oDistList As Outlook.DistListItem Dim oContact As Outlook.ContactItem Dim oItems As Outlook.Items Set oItems = Application.GetNamespace("mapi").GetDefaultFolder( olFolderContacts).Items ' Obtain List of DL's ''--- Would prefer this method as it seems it would be a faster way For Each oDistList In oItems Debug.Print oDistList.DLName, oDistList.MemberCount '--- Runtime Error '13' at this line (Next) Next '---This loop works fine For Each obj In oItems If TypeOf obj Is Outlook.DistListItem Then Set oDistList = obj Debug.Print oDistList.DLName, oDistList.MemberCount End If Next |
#5
|
|||
|
|||
![]()
Declaring the object as a DL only early binds it to that type of object. If
you try to assign a contact to a DL object you get an error. No filtering is involved in declarations. The MessageClass for a DL is "IPM.DistList", so your restriction filter would look like this: strFilter = "[MessageClass] = 'IPM.DistList'" Dim colFiltered As Outlook.Items Set colFiltered = oItems.Restrict(strFilter) For Each oDistList In colFiltered 'blah, blah Next -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Zarqy" wrote in message ups.com... Also, doesn't the Dim oDistList As Outlook.DistListItem ... For Each oDistList In oItems already act as a filter? Zarqy wrote: Ken, the Restrict look simple enough, but I am lost with the "MessageClass for a DL" part. in my example would I still use the oDistList? For Each oDistList.Restrict("[???] = 'DistListItem' ") in oItems ... Is this even close? I'm sure once I see this in action it will make sense, but right now it is as clear as muddy water. I see something, but not sure its the right thing. |
#6
|
|||
|
|||
![]()
Ken,
THANK YOU! That filter has sped up my code incredibly! I no longer have to loop thru every contact just to check the dl's members. I've been programming in VB for years, and for some reason the early/late binding concept has always been on the fringe of making sense to me. Your explanaition is another step in my comprehension. Ken Slovak - [MVP - Outlook] wrote: Declaring the object as a DL only early binds it to that type of object. If you try to assign a contact to a DL object you get an error. No filtering is involved in declarations. The MessageClass for a DL is "IPM.DistList", so your restriction filter would look like this: strFilter = "[MessageClass] = 'IPM.DistList'" Dim colFiltered As Outlook.Items Set colFiltered = oItems.Restrict(strFilter) For Each oDistList In colFiltered 'blah, blah Next -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Zarqy" wrote in message ups.com... Also, doesn't the Dim oDistList As Outlook.DistListItem ... For Each oDistList In oItems already act as a filter? Zarqy wrote: Ken, the Restrict look simple enough, but I am lost with the "MessageClass for a DL" part. in my example would I still use the oDistList? For Each oDistList.Restrict("[???] = 'DistListItem' ") in oItems ... Is this even close? I'm sure once I see this in action it will make sense, but right now it is as clear as muddy water. I see something, but not sure its the right thing. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Runtime Error | Mel | Outlook Express | 2 | June 25th 06 05:43 AM |
IE 6.0 Runtime Error | Platebanger | Outlook Express | 2 | April 14th 06 12:50 PM |
runtime error! X | chula819 | Outlook Express | 1 | March 24th 06 12:27 PM |
runtime error! X | chula819 | Outlook Express | 0 | March 24th 06 08:28 AM |
Runtime error | KENNETH M LONG | Outlook Express | 3 | January 19th 06 11:18 PM |