Link access to Active Directory

aron.ridgway

Registered User.
Local time
Today, 21:14
Joined
Apr 1, 2014
Messages
148
Just wondering if anybody has had any luck linking to an active directory.
I want to link into the active directory to get a list of staff usernames, so it will update the user table as new members of staff are created etc.

We currently have around 130 staff, so rather than manually updating the user table i want it to pick up the usernames from AD?
 
This code will query Active Directory and pull the results into a recordset. From there you can do whatever you need to do with it.

Code:
Public Function GetUsersFromAD()
Dim objConnection As Object
Dim objCommand As Object
Dim objRecordset As Object

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") = 2

objCommand.CommandText = "SELECT DisplayName, Mail, sAMAccountname FROM 'LDAP://domain.com' WHERE objectCategory='user'"    'Change the domain to match your domain

Set objRecordset = objCommand.Execute

'Do whatever you want to do with the recordset here

objRecordset.Close
Set objRecordset = Nothing
End Function
 
I have posted several times at this forum on this subject.

Search the forum for LDAP and my username.
 

Users who are viewing this thread

Back
Top Bottom