Hi
I'm using Access 2010 to populate a table with all users information from active directory. I use the following code but somehow this does not seem to work. Help please.
Function PopulateADSData()
Const ADS_SCOPE_SUBTREE = 2
Dim objRecordSet As Object
' ADODB Connection to AD
Dim objConnection As ADODB.Connection
Dim objCommand As ADODB.Command
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 = "<<a href="ldap://dc=enterprisenet,dc=org>;(objectCategory=person">LDAP://dc=enterprisenet,dc=org>;(objectCategory=person);" & "adsPath;subtree"
'"SELECT Name FROM 'LDAP://dc=enterprisenet,dc=org' WHERE objectClass='user' AND objectCategory='Person'"
Set objRecordSet = objCommand.Execute
'MsgBox objRecordSet.RecordCount
'objRecordSet.MoveFirst
Dim DB As DAO.Database
Dim qry1 As DAO.QueryDef
Dim rst1 As DAO.Recordset
Set DB = CurrentDb
Set qry1 = DB.CreateQueryDef("")
qry1.SQL = "DELETE * FROM ADUsers"
qry1.Execute
qry1.SQL = "Select * FROM ADUsers"
Set rst1 = qry1.OpenRecordset
Do Until objRecordSet.EOF
Set objItem = GetObject(objRecordSet.Fields("Adspath"))
rst1.AddNew
rst1.Fields("Display Name") = objItem.DisplayName
rst1.Fields("LANID") = objItem.samaccountname
rst1.Fields("Email") = objItem.mail
rst1.Update
'rst1.MoveNext
Loop
MsgBox "Completed"
End Function