Creating a Distribution List Programatically with ole

P

Pat Curran

Hi;

I use visual dbase and am confused about creating a distribution list with
my employees. I add all my employees to my Outlook Contacts using the
following code:
myOlApp=new oleautoclient('outlook.application')
olMAPI=myOlApp.GetNameSpace("MAPI")
if type("myOlApp.Assistant") # 'O'
myFolder.Display()
endif
Myfolder = olMAPI.getdefaultfolder(10) && Contacts
myitems = myfolder.items
myItem= myOlApp.CreateItem(2)
myItem.firstname = 'JOHN'
myItem.lastname = 'DOE'
myItem.Hometelephonenumber = ltrim(rtrim(Contacts->localphone))
myItem.governmentidnumber = ltrim(rtrim(Contacts->ssan))
myItem.save()

I now want to create distribution lists, and am having a very difficult time
doing so. I can use the following code to create the item:

oOutlook = new oleAutoClient("outlook.application")
oItem = oOutlook.createItem(7)
oItem.dlname = 'Empolyees'
oItem.save()
oItem.Display()

Now I can view the distribution list. The problem I am having, is how do I
add the members programatically? The members are in my contacts folder.
Assuming that a contacts first name is 'John' and his last name is 'Doe' How
would he be added? I tried:
oItem.recipients.add = 'DOE, JOHN' but it doesnt work. I also tried:
oItem.AddMembers = 'DOE, JOHN' and I recieve an error stating the object
property is read only. Any help would be appreciated.

Pat
 
S

Sue Mosher [MVP]

AddMembers requires a Recipents collection as its object. An easy way to get
one is to use a new message:

Set myMail = myOlApp.CreateItem(0)
Set colRecip = myMail.Recipients
colRecip.Add ("JOHN DOE")
colRecip.ResolveAll
oItem.AddMembers colRecip
myMail.Close olDiscard

Note that JOHN DOE can't be added to the DL unless he has an email address.
 

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