Adding a distribution list to a distributionlist (distlistitem)

  • Thread starter Søren Godthardt Hansen
  • Start date
S

Søren Godthardt Hansen

Hey.

I need to add a distlistitem (a distribution list) as a sublist to another
distribution list, but I can't seem to find a method in the API which is
allowing it.

I have no problems adding recipients to the list, but I have come across a
limit to distribution lists at about 2KB (around 100 members), so therefore
I need build a list from a number of sublist.

Please help !

Søren
 
S

Sue Mosher [MVP-Outlook]

Same method: Created a resolved Recipient using that DL.

The real question is whether a DL is an appropriate solution at all, given the management headaches.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Søren Godthardt Hansen

Hey Sue.

Thank you for the answer - I bought your book "Microsoft Outlook
Programming", and found it extremely interesting - unfortunately it doesn't
answer this question.

When I try to cast a distlistitem to a recipient using the
distlistitem.addMember, I recieve a runtime error (as I would expect) - what
have I missed ??

The solution will not generate management headaches, since it is a read-only
export from a CRM (not MS) -database.

Best regards

Søren

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Same method: Created a resolved Recipient using that DL.

The real question is whether a DL is an appropriate solution at all, given
the management headaches.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Could you show a code snippet, please?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Søren Godthardt Hansen said:
Hey Sue.

Thank you for the answer - I bought your book "Microsoft Outlook
Programming", and found it extremely interesting - unfortunately it doesn't
answer this question.

When I try to cast a distlistitem to a recipient using the
distlistitem.addMember, I recieve a runtime error (as I would expect) - what
have I missed ??

The solution will not generate management headaches, since it is a read-only
export from a CRM (not MS) -database.

Best regards

Søren

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Same method: Created a resolved Recipient using that DL.

The real question is whether a DL is an appropriate solution at all, given
the management headaches.
 
S

Søren Godthardt Hansen

Hey Sue.

Sub CreateDistList()
'Try to add a distribution list to a distribution list

Dim olApp As Outlook.Application
Dim objItem As DistListItem
Dim objItem2 As DistListItem
Dim objRcpnt As Recipient
Dim TempItem As Outlook.MailItem

Set olApp = Outlook.Application
Set TempItem = olApp.CreateItem(olMailItem)



'Create recipient for list
Set objRcpnt = TempItem.Recipients.Add("(e-mail address removed)")
objRcpnt.Resolve

'Create a distribution list
Set objItem = olApp.CreateItem(olDistributionListItem)
objItem.DLName = "Main DistList"
objItem.Save

'Create another list to be added til the first (main)
Set objItem2 = olApp.CreateItem(olDistributionListItem)
objItem2.DLName = "Sub DistList"
objItem.AddMember objRcpnt
objItem2.Save

'OK - so fare


'This generates a type error (as I would expect)
objItem.AddMember objItem2
objItem.Save

End Sub


"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Could you show a code snippet, please?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Søren Godthardt Hansen said:
Hey Sue.

Thank you for the answer - I bought your book "Microsoft Outlook
Programming", and found it extremely interesting - unfortunately it
doesn't
answer this question.

When I try to cast a distlistitem to a recipient using the
distlistitem.addMember, I recieve a runtime error (as I would expect) -
what
have I missed ??

The solution will not generate management headaches, since it is a
read-only
export from a CRM (not MS) -database.

Best regards

Søren

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Same method: Created a resolved Recipient using that DL.

The real question is whether a DL is an appropriate solution at all, given
the management headaches.
 
S

Sue Mosher [MVP-Outlook]

objItem2 is a DistListItem, not a Recipient. You can use CreateRecipient to return a Recipient object from objItem2:

Set recip = Application.Session.CreateRecipient(objItem2.Subject)

If the name of the DL is not unique or if the DL is not in a folder used for address solution, it won't resolve into a Recipient.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Søren Godthardt Hansen said:
Hey Sue.

Sub CreateDistList()
'Try to add a distribution list to a distribution list

Dim olApp As Outlook.Application
Dim objItem As DistListItem
Dim objItem2 As DistListItem
Dim objRcpnt As Recipient
Dim TempItem As Outlook.MailItem

Set olApp = Outlook.Application
Set TempItem = olApp.CreateItem(olMailItem)



'Create recipient for list
Set objRcpnt = TempItem.Recipients.Add("(e-mail address removed)")
objRcpnt.Resolve

'Create a distribution list
Set objItem = olApp.CreateItem(olDistributionListItem)
objItem.DLName = "Main DistList"
objItem.Save

'Create another list to be added til the first (main)
Set objItem2 = olApp.CreateItem(olDistributionListItem)
objItem2.DLName = "Sub DistList"
objItem.AddMember objRcpnt
objItem2.Save

'OK - so fare


'This generates a type error (as I would expect)
objItem.AddMember objItem2
objItem.Save

End Sub
When I try to cast a distlistitem to a recipient using the
distlistitem.addMember, I recieve a runtime error (as I would expect) -
what
have I missed ??

The solution will not generate management headaches, since it is a
read-only
export from a CRM (not MS) -database.

Best regards

Søren

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Same method: Created a resolved Recipient using that DL.

The real question is whether a DL is an appropriate solution at all, given
the management headaches.
 
Joined
Mar 25, 2009
Messages
1
Reaction score
0
Dear friends,I have a question.I have added the name of the sub distribution list to the main distribution list in graphical interfaces. But I don't know how to actualize that with VBA programe. Help me,please!
Thank you!
 

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