Hi
I tried the following code below. It works perfectly OK with less
email addresses (5 or 10) but when the list gets large (eg 50 plus
addresses) it does not work. It creates an empty distribution list.
Am I missing here something or is there a limit for exporting more
number of email addresses?
Pre reqs: Access 2000, Outlook 2000
Create a table named "tblEmailaddresses" with only one column named
"email" in Access
Create a form named "frmAddEmails" with a command button "cmdAdd"
Populate "tblEmailaddresses" with say 80 email addresses eg
[email protected],
[email protected] etc.
Put this code behind the command button's click event.
Option Compare Database
Private Sub cmdAdd_Click()
On Error GoTo ErrHandler
Dim txtDistName As String
txtDistName = InputBox("Enter the name of New Distribution List",
"Enter distribution List Name", "DistributionList1")
If txtDistName = "" Then Exit Sub
Dim ola As Outlook.Application
Dim dli As Outlook.DistListItem
Dim myTempItem As Outlook.MailItem
Dim myRecipients As Outlook.Recipients
Dim tblEmailTable As Object
Set ola = CreateObject("Outlook.Application")
Set dli = ola.CreateItem(olDistributionListItem)
Set myTempItem = ola.CreateItem(olMailItem)
Set myRecipients = myTempItem.Recipients
Set tblEmailTable = CurrentDb.OpenRecordset("tblEmailAddresses")
If tblEmailTable.BOF Then GoTo exit_createDL
tblEmailTable.MoveFirst
Do
myRecipients.Add tblEmailTable!email
tblEmailTable.MoveNext
Loop Until tblEmailTable.EOF
dli.AddMembers myRecipients
dli.DLName = txtDistName
dli.Close olSave
myTempItem.Close olDiscard
exit_createDL:
Set myTempItem = Nothing
Set myRecipients = Nothing
Set dli = Nothing
Set ola = Nothing
tblEmailTable.Close
Set tblEmailTable = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbOKOnly, "There was an error!!"
End Sub
Please can you also advise/suggestions on coding style, error trapping
etc
many thanks
MS