Set listbox control source to recordset

C

Chuck

How can I set the ControlSource property of a list box to be a recordset? I
have a recordset that is essentially a LDAP query on an Active Directory
domain and I'd like to fill a list box control with that recorset. Here is
what I have so far. I can navigate within the recordset (with movenext,
etc) to get individual records but I'm having a hard time displaying the
entire recordset in a list box or even a form. Here's what I have so far:


Dim objConnection, objCommand
Dim strQuery

' Use ADO to search the domain for all users.
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

strQuery =
"<LDAP://mydomaincontroller/OU=Users,OU=ou1,OU=ou2,DC=myorg,DC=com>;(&(objectCategory=person)(objectClass=user));displayName;subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

Me.MyListBox.ControlSource = ????




Thanks
 
D

Dan Artuso

Hi,
You don't say which version of Access you're using but I know that 2003 and 2002 have an
AddItem property so you can iterate through your rs and simply add items.

If not, you could probably put the rs into a table and then make the table the record source
of the listbox
 
C

Chuck

Hey Dan from NRC,

Yes I know that is how I can do it but I was hoping there was a simpler way.

Thanks

Chuck
 

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