Mail merge and Active Directory

M

Mike

I would like to setup word 2007 to use Active Directory objects for a mail
merge.

Winthin word, select recipients, I have started to create a data connection
using the "OLE DB proider for Microsoft Directory Services" but cannot get it
to work and have not managed to find any documentation with regard what to
put in the Data Source or location fields in the setup wizard.
 
P

Peter Jamieson

This is my post from a couple of years ago on this subject - I can't say
I've looked at this area since then:

------------------------------
The last time I looked (about 2 years ago) it was possible to use the OLEDB
provider for the AD to use AD as a Word mailmerge data source. e.g. in code

ActiveDocument.MailMerge,OpenDataSource _
Name:="c:\a\empty.odc", _
Connection:="Provider=ADSDSOObject;", _
SQLStatement:="SELECT * FROM 'LDAP://adsiservername'"


where empty.odc is a completely empty file that you can create in e.g.
Notepad, and adsiservername is the name of the adsi server box.


However, I get the impression that what you want to do is either
a. get some ADSI data corresponding to the individual/login name of the
person doing the merge or
b. get some ADSI data appropriate to the data in each row in another data
source.


Either way, for the data to appear as a field in the data source, you would
have to be able to get the data source to do the ADSI query. If your data
source is Jet/Access, you /might/ be able to create a Query that could do
that, using a linked table perhaps - I don't know off the top of my head. If
your data source is something like SQL Server, you /might/ be able to do the
same using an attached table and a View.


Otherwise, if it's case (a), you could consider getting the data using ADO
in a Word VBA macro each time a merge is done, and either inserting the
results directly or storing them in a way that makes insertion relatively
simple, e.g. in a Document Property (insert using { DOCPROPERTY } field or
Document Variable (insert using { DOCVARIABLE } field.
 
M

Mike

Hi James,

Thanks for the reply.

I have sucessfully connected to AD before within scripts using the sort of
syntax you use below, but this time I am using the wizards within word 2007,
and my aim is for users to interactivly undertake a mail merge using Active
directory as the source of contacts rather than a public folder in Exchange.

Within word I am undertaking the following:
* Mailings tab.
* Select recipients option.
* Use existing list.
* click on "+Connect to new Data Source.odc"
* click on "other/advanced".
* select "OLE DB Provider for Microsoft Directory services".
* press next to get to the Connections page of "Data link properties".

Its on this page I cannot config the correct options for Data Source and
Location.

Cheers.
Mike.
 
P

Peter Jamieson

I understand what you are trying to achieve but I do not know what should go
in those fields either, and it is also possible that nothing you put in
there will make Word connect to that data source. The trouble is I think
that both Word and Excel (which is usually a bit better at opening .odc type
files) expect one of several things to happen when they open a .odc, and
none of them does in this case. e.g. Word can open a .odc that specifies a
database /in the connection string/ but no table, but only if the data
source can then provide a list of available tables. Or Word can open a .odc
where a table is specified. But in this case, possibly because of the nature
of ADSI itself, you do not specify a particular directory via the connection
string, and the provider cannot provide a list of tables. Nor have I found
any way to specify "a table" in a way that works with either Word or Excel.

(That certainly does not mean that it is not do-able, but the syntax for
connecting to directories, both via LDAP and using MS's SQl dialect, is
obscure enough that it is difficult even to work out things that might
plausibly work).

So in any case, your users would have to be able to form an LDAP or SQL
query to query your directory. If they know how to do that, all you really
have to do is provide a bit of Word VBA that prompts for the query and
issues the OpenDataSource command that I've provided (except there's an
error in it - it should be

ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\a\empty.odc", _
Connection:="Provider=ADSDSOObject;", _
SQLStatement:="SELECT * FROM 'LDAP://<the name of your ADSI server>'"

).
 

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