Excel SQL and listbox

  • Thread starter Thread starter Ravi
  • Start date Start date
R

Ravi

I have an Excel 2000 list from which I want to run a SQL statement to select
unique values (ie. with SELECT DISTINCT ). My question is, how can I fill a
listbox with the resulting result list?
I want to achieve this without pasting the unique values on a worksheet.

Thanks for any help,
Ravi
 
Ravi,
Use ADO.
Set a reference to "MS Active Data Objects 2.x"
Dim Conn As ADODB.Connection
Dim RS As ADODB.Recordset

Check the help about setting/creating a connection.

Set RS=Conn.Execute(SQLString)

As for adding, you loop through the RS, adding to the listbox

List1.Clear
With RS
.MoveFirst
List1.AddItem .Fields(1).Value
.MoveNext
End With

NickHK
 

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

Back
Top