问题描述:

I run an LDAP Query in VBA and obtain an Object with the match using GetObject:

Set colOU = GetObject("LDAP://OU=LazyPeople,DC=somecompany,DC=com")

colOU.Filter = Array("user")

I have been looping through the colOU using a For Each statement:

For Each objADObject In colOU

However, what I need to do is present a ListBox with the name of each user from the colOU and have the user choose an entry. Then I want to go back to that instance, (objADObject) from colOU that corresponds to the user selection and manipulate the properties.

What I would like to do is store an index for each objADObject in each entry of the ListBox, and use that index to recall that instance from colOU after the user makes a selection. However, I cannot find a way of accessing colOU items by index, (.Items, .Item, .Members, .Count, and UBound generate errors). I have been unsuccessful in trying to cast or convert colOU to a collection as well.

Any suggestions?

Also, how can I investigate an object in VBA to find out if can be enumerated, (what in .NET I would call an IEnumerable).

Thanks.

网友答案:

Okay, I have figured this one out.

Apparently, you can take the colOU object and do a:

Set objADObject = colOU.GetObject("user", <RelativeDistinguishedName>)

and it will set the objADObject to the correct user object. So, I assigned objADObject.name (which is the RelativeDistinguishedName) to a hidden column 2 of the ListBox. When I retrieve the value from the hidden column, I can just pass it as a variable to colOU.GetObject and I will have a reference to the correct user object.

Huzzah!

However, I would still like to know if colOU can be enumerated if anyone knows the answer.

相关阅读:
Top