views:

444

answers:

2

At work we have Windows Server 2003. In my access database, I need to link to the user / group data so that it can populate a drop-down list and can thus be associated with database records. Does anyone know how to do this?

Thanks,

Chris

A: 

I've never done it, but I have read that involves LDAP queries over ADO, but don't know the actual provider name or the connect strings needed. You might search this site for articles about LDAP queries to AD for some examples. They won't be Access answers, but they might show you what to do in Access.

David-W-Fenton
A: 

Hi,

Try something like this:

    'Use ADO and LDAP to return all users in Active Directory
Dim objRecordSet As Object
Dim objCommand As Object
Dim objConnection As Object

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort On") = "Name"

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://dc=<enter domain controler server name here>,dc=<enter full AD domain name here>' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Debug.Print objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop

This should get the list of users. Note you will have to supply the domain controller server name and AD Domain name.

Hope this helps Mark

Mark3308