DL Listing REVISITED -- CODE INCLUDED

J

Jeff Rush

Hi All,

I hate to post the same question to two NG's but after posting the first one
it seems more appropriate to this NG.

I have been struggeling with this beast for some time now and have yet to
get this to work the way I would like..

I can get the recipients list and walk through it. The code below works.
However if I do MyRecipient.Members(x) I am unable to get a reliable count
or properly pull the name and address list values from them.

I have tried code similar to the following:

For i = 1 To myolsel.Count
Set myrecip = myolsel(i)

If myrecip.Recipients.AddressEntries.Members.Count > 1 Then

For Each entry In myrecip.Recipients.AddressEntry.Members
mystr = mystr & Chr$(13) + myrecip.AdressEntry.Members.Name
mystr = mystr & "; " & myrecip.AdressEntry.Members.Address
Next

End If

Next

This did not work either.
Any help would be greatly appreciated!!

Jeff



Here is my code as it stands.
===================================================
===================================================
Private Sub DLBreakout()

Dim MyBodStr As String

'Set Variable to select the default INBOX folder
Set myFolder = Session.GetDefaultFolder(olFolderInbox)

'Set variable to the (collection of) selected items in Inbox.
Set myolsel = Application.ActiveExplorer.Selection

'Set Source and Target forms
Set myolsel = Application.ActiveExplorer.Selection
Set targetitem = myFolder.Items.Add("ipm.note.dllist")
Set sourceitem = myolsel(1)

'Get Recipient List from Source Item
Set myrecip = sourceitem.Recipients

'count the recipients
MyRecipNum = myrecip.Count

'If the recipients list is not empty
If MyRecipNum > 0 Then

'For Each Recipient Do the following:
For x = 1 To MyRecipNum

MyBodStr = MyBodStr & (vbCrLf & myrecip(x).Name)

'==========================================================================
'**************************************************************************
'==========================================================================
' Need Code Here to determine if recip is a DL and if so
' Enumerate the list to MyBodStr
'==========================================================================
'**************************************************************************
'==========================================================================

Next x

'If Myrecip =< 0
Else
MsgBox ("There are no Recipients in this message.")
End If
'Write Recipient information to DL
targetitem.Body = MyBodStr
targetitem.Display

End Sub
 
S

Sue Mosher [MVP]

Dumb question, but exactly what is it you're trying to accomplish?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
J

Jeff Rush

Specifically I have the following code that is giving me errors:

MyCount = myrecip.AddressEntry.Members.Count

This line give me object doesn't support property or method.

Then I have the following code...

For x = 1 To MyRecipNum

MyBodStr = MyBodStr & (vbCrLf & myrecip(x).Name)

MyCount = myrecip.AddressEntry.Members.Count

'If the current recipient has members ie is a DL then do the following:
If MyCount > 1 Then
MsgBox ("Item Has " & MyCount & " members.")

For i = 1 To MemCount

'Put Users Name in the string
MyBodStr = MyBodStr & (vbCrLf & myrecip(x).Members(i).Name)

'Put Users Email Address in the String
MyBodStr = MyBodStr & (" " & myrecip(x).Members(i).Address)

'Gimme a Line!
MyBodStr = MyBodStr & vbCrLf

Next

'End MyRecip IF
End If

Next x

I am unable to get this to work with the framework in my previous post.

Any thoughts??

Thanks again!!

Jeff
 
S

Sue Mosher [MVP]

My question was what this code is supposed to accomplish. I'm missing the big picture here.
 
J

Jeff Rush

Hi Sue,

I am trying to list the members of the DL in to the new mail message.

Thanks,

Jeff.

My question was what this code is supposed to accomplish. I'm missing the
big picture here.
 
S

Sue Mosher [MVP]

I think part of the problem may be that your code wasn't checking whether the recipient wasn't a DL and wasn't handling the error that would occur if it was not a DL but you tried to access the Members collection. See if this helps clarify things. It's a simple routine that takes a message as an argument and, if any DLs are present, builds a list of their members and then displays that list in a message box.

Sub EnumDLs(objMail As MailItem)
Dim strList As String
Dim objRecip As Recipient
Dim objAE As AddressEntry
Dim objMemAE As AddressEntry
For Each objRecip In objMail.Recipients
Set objAE = objRecip.AddressEntry
If objAE.DisplayType = olDistList Then
For Each objMemAE In objAE.Members
strList = strList & objMemAE.Name & "," & objMemAE.Address & vbCrLf
Next
End If
Next
MsgBox strList
Set objMemAE = Nothing
Set objAE = Nothing
Set objRecip = Nothing
End Sub

Note that the address will be the X.400 address. If you want the SMTP address, then you need to use essentially the same technique but with CDO or (better yet, to avoid security prompts) Redemption and use the Fields collection to get the value of the PR_EMAIL MAPI tag, as demonstrated in the sample at http://www.cdolive.com/cdo5.htm#EMailAddressOfSender
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
J

Jeff Rush

Beauty! That is just what I needed.

THANK YOU!!
It's working now.

I think part of the problem may be that your code wasn't checking whether
the recipient wasn't a DL and wasn't handling the error that would occur if
it was not a DL but you tried to access the Members collection. See if this
helps clarify things. It's a simple routine that takes a message as an
argument and, if any DLs are present, builds a list of their members and
then displays that list in a message box.
 

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