Hi, I have a recordset that I pull in from ActiveDirectory into a combobox. This works great now, but it doesn’t come in in alphabetical order. There is a .Sort property which I thought would work, and is used in some sample code on MSDN, but when I try to compile it I get an error indicating Invalid Property. Following is the code I am using:
Private Sub GetUserList()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim oRoot As IADs
Dim oDomain As IADs
Dim sBase As String
Dim sFilter As String
Dim sDomain As String
Dim sAttribs As String
Dim sDepth As String
Dim sQuery As String
Dim user As IADsUser
On Error GoTo ErrHandler:
Set oRoot = GetObject(“LDAP://rootDSE”)
‘Work in the default domain
sDomain = oRoot.Get(“defaultNamingContext”)
Set oDomain = GetObject(“LDAP://” & sDomain)
sBase = “”
‘Get record set
sFilter = “(&(objectCategory=person)(objectClass=user)(extensionattribute1=*))”
sAttribs = “extensionattribute1,Description”
sDepth = ADS_SCOPE_SUBTREE
sQuery = sBase & “;” & sFilter & “;” & sAttribs & “;” & sDepth
conn.Open “Data Source=Active Directory Provider;Provider=ADsDSOObject”
Set rs = conn.Execute(sQuery)
rs.CursorLocation = adUseClient
rs.Sort “extensionattribute1” ‘(ASC is the default, which is what I want here)
On Error Resume Next
rs.MoveFirst
While Not rs.EOF
cboAuthor.AddItem rs.Fields(0).Value
rs.MoveNext
Wend
RoutineExit:
Exit Sub
ErrHandler:
On Error Resume Next
If Not rs Is Nothing Then
If rs.State 0 Then rs.Close
Set rs = Nothing
End If
If Not conn Is Nothing Then
If conn.State 0 Then conn.Close
Set conn = Nothing
End If
Set oRoot = Nothing
Set oDomain = Nothing
Resume RoutineExit
End Sub
Any ideas why VBA won’t take the property which it even brings up using its AutoComplete feature? Arrgghh!