msearly
05-05-2004, 11:12 AM
Is there any reason why this code should not work?
Public Function AddMemberToDL(sDlName As String, sEntryName As String, sEmailAddress As String) As Boolean
On Error GoTo err_AddMemToDL
Dim oContacts As Outlook.MAPIFolder
Dim oDList As Outlook.DistListItem
Dim oRecipient As Outlook.Recipient
Dim oMailItem As Outlook.MailItem
AddMemberToDL = True
'I log onto Outlook and establish the value of olNS elsewhere in my program. (olNS = Outlook.NameSpace).
Set oContacts = olNs.GetDefaultFolder(olFolderContacts)
Set oDList = oContacts.Items(sDlName)
Set oMailItem = olApp.CreateItem(olMailItem)
Set oRecipient = oMailItem.Recipients.Add(sEntryName)
With oRecipient
.AddressEntry.Type = "SMTP"
.AddressEntry.Address = sEmailAddress
.Resolve
End With
oDList.AddMembers oMailItem.Recipients
'If I do a "oDList.show" right here, it shows me the distribution list with the entry in it, but I have to click on the Update button to get the list to save the entry. This would be fine if I only had a user or two to add, but I have nearly a thousand to do. How do I progmatically do what clicking on the update button in Outlook does?
oDList.Save
Exit Function
err_AddMemToDL:
AddMemberToDL = False
MsgBox "Error adding recipient to DL List." & vbLf & "Entry Name: " & sEntryName & vbLf & "DL: " & sDlName & vbLf & err.Description
End Function
This function returns no errors but it does not save the entry in the distribution list.
Thanks
Matt Early
Network Administrator
Prince Edward County Public Schools
Farmville, VA
Public Function AddMemberToDL(sDlName As String, sEntryName As String, sEmailAddress As String) As Boolean
On Error GoTo err_AddMemToDL
Dim oContacts As Outlook.MAPIFolder
Dim oDList As Outlook.DistListItem
Dim oRecipient As Outlook.Recipient
Dim oMailItem As Outlook.MailItem
AddMemberToDL = True
'I log onto Outlook and establish the value of olNS elsewhere in my program. (olNS = Outlook.NameSpace).
Set oContacts = olNs.GetDefaultFolder(olFolderContacts)
Set oDList = oContacts.Items(sDlName)
Set oMailItem = olApp.CreateItem(olMailItem)
Set oRecipient = oMailItem.Recipients.Add(sEntryName)
With oRecipient
.AddressEntry.Type = "SMTP"
.AddressEntry.Address = sEmailAddress
.Resolve
End With
oDList.AddMembers oMailItem.Recipients
'If I do a "oDList.show" right here, it shows me the distribution list with the entry in it, but I have to click on the Update button to get the list to save the entry. This would be fine if I only had a user or two to add, but I have nearly a thousand to do. How do I progmatically do what clicking on the update button in Outlook does?
oDList.Save
Exit Function
err_AddMemToDL:
AddMemberToDL = False
MsgBox "Error adding recipient to DL List." & vbLf & "Entry Name: " & sEntryName & vbLf & "DL: " & sDlName & vbLf & err.Description
End Function
This function returns no errors but it does not save the entry in the distribution list.
Thanks
Matt Early
Network Administrator
Prince Edward County Public Schools
Farmville, VA