PK,
Thanks I did use your method as a start and shared it with others.
I thought I would share with you what they told me.
I only use a few parts of the entire thing specifically the part about getting user information from AD.
I quote another fellow
"realistically to get your import to run a bit faster , you'd probably be better off running an INSERT INTO SQL statement:"
INSERT INTO AD_User (UserName, FirstName, LastName, BusinessPhone, DisplayName, LogonName)
SELECT Name,givenName,SN,telephonenumber,displayname,sAMA ccountName
FROM 'LDAP://OU=,DC=,
WHERE objectCategory='user'"
It was true the way you wrote it worked but this did help it speed up. In my case I have about 2000+ users I am importing.
Non the less thanks. for that.
Also I did figure out how to query AD from a combo/listbox
Again folks were digesting what i gathered from you and had some sugestions.
So here is my end result:
The Code below is added to a combo box called lstUsers on a form in the OnGotFocus Event. When you run the form it will query AD when you put your mouse in the box. After the query runs you can see the names of users in your AD in the combo box.
NOTE:********
I excluded the LDAP just know that you need to add in your own domain.
A few extra notes:
1. This could not work for me because the Value list in a combo box
is limited to like 30 something thousand characters.
and for 2000+ users this is reached.
But if your users are less than lets say 100 this should work fine for you.
2. I wanted to see 6 columns in AD but you can change that to whatever
suits. You can also and change the SQL to get other info that you need from AD.
So whats the point? I had to see if it was possible wether it worked for my scenario or not.
In the end I hope this helps someone.
Private Sub lstUsers_GotFocus()
'*****************************************
'*Connects To AD and sets search criteria*
'*****************************************
'On Error Resume Next
Dim rs As ADODB.Recordset
Dim strSql As String
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
'************************************************* *********************
'*SQL statement on what OU to search and to look for User Objects ONLY*
'************************************************* *********************
objCommand.CommandText = _
"SELECT Name,givenName,SN,telephonenumber,displayname,sAMA ccountName " _
& "FROM 'LDAP://OU=,DC=' WHERE " _
& "objectCategory='user'"
'*************************************
'Adds records to list box
'*************************************
With Me!lstUsers
.RowSourceType = "Value List"
.ColumnCount = 6
End With
Set objrecordset = objCommand.Execute
With objrecordset
.MoveFirst
Do While Not .EOF
Me!lstUsers.AddItem .Fields("Name").Value & ";" & _
.Fields("GivenName").Value & ";" & _
.Fields("SN").Value & ";" & _
.Fields("telephonenumber").Value & ";" & _
.Fields("DisplayName").Value & ";" & _
.Fields("sAMAccountName").Value
.MoveNext
Loop
End With
objrecordset.Close
Set objrecordset = Nothing
End Sub