Query AD & fill combo box

  • Thread starter epoh97 via AccessMonster.com
  • Start date
E

epoh97 via AccessMonster.com

I am trying to query Active Directory and AddItems to the combo box.

Private Sub Form_Load()

Dim objConnection
Dim objCommand
Dim objRecordSet
Dim strTwoWeeksAgo
Dim dtmDate
Dim i
Dim User

dtmDate = Date - 14

strTwoWeeksAgo = CStr(Year(dtmDate)) & CStr(Month(dtmDate)) _
& CStr(Day(dtmDate)) & "000000.0Z"

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, createTimeStamp" _
& " FROM 'LDAP://dc=DOMAIN,dc=com' " _
& "WHERE createTimeStamp >= '" & strTwoWeeksAgo & "' " _
& "AND objectCategory= 'person' AND objectClass = 'user'"


Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF

User = objRecordSet.Fields("Name").Value

Me.QryNewUsers.AddItem Item:=User, Index:=0


objRecordSet.MoveNext
i = i + 1
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top