Hi
I would like to get a list of all the users in the active directory and put them in a combo box. Does anyone know how to do this?
I would like it to show there CN name
Thanks
Hi
I would like to get a list of all the users in the active directory and put them in a combo box. Does anyone know how to do this?
I would like it to show there CN name
Thanks
Pulled this from the depths of my swiss cheese mind....
pkstormy posted a zip of AD code in the code-repository section of this forum on 08-28-2010.
The posting name is "Active Directory coding"
https://www.accessforums.net/code-re...ding-7691.html
Thank you for putting me in the right direction.
A user called Galaxiom gave me this code and it does exactly what I want:
Option Compare Database
Option Explicit
Public Function UserRecordset() As Object 'ADODB.Recordset
Const adCmdText = 1
Const adUseClient = 3
Dim ADConn As Object ' ADODB.Connection
Dim ADCommand As Object ' ADODB.Command
Dim ADUser As Object ' ADODB.Command
Dim DomainDN As String
DomainDN = CreateObject("LDAP://rootDSE").Get("defaultNamingContext")
Set ADConn = CreateObject("ADODB.Connection")
With ADConn
.CursorLocation = adUseClient
.Provider = "ADsDSOObject"
.Open "Active Directory Provider"
End With
Set ADCommand = CreateObject("ADODB.Command")
With ADCommand
.ActiveConnection = ADConn
.CommandType = adCmdText
.CommandText = "SELECT CN FROM 'LDAP://" & DomainDN & "' WHERE objectCategory='User' AND CN<>'IWAM_*' AND CN<>'IUSR_*' ORDER BY CN"
End With
Set ADUser = ADCommand.Execute
Set ADUser.ActiveConnection = Nothing
Set UserRecordset = ADUser
ADConn.Close
Set ADConn = Nothing
Set ADCommand = Nothing
End Function
You can then make this module the record set for a combo box
I like it. One connection, a couple commands, and a string.