ADO copy from SQL Server into Excel 2003 List Box

  • Thread starter Thread starter christopher ward
  • Start date Start date
C

christopher ward

Dear Experts

I am trying to execute some very simple sql from vba. The sql is

USE master;
SELECT NAME FROM sysdatabases

I want to then place the results in a list box on a vba form

To do this I am looking at recordsets and ado where I cannot find a decent
documented method i can work with. So far I have created


soucon = "Provider=" & Master.TextBox22.Value & ";Data Source=" &
Master.TextBox23.Value _
& ";Initial Catalog=" & Master.TextBox24.Value & ";User id=" &
Master.TextBox25.Value _
& ";Password=" & Master.TextBox26.Value

Set ConSource = CreateObject("ADODB.Connection")
ConSource.Open soucon

which i believe works and connects to Master - how do i now create a
recordset and populate my list box is my question ?

If you respond thank you for your time and efforts as always


kind regards
 
dim rs as ADODB.recordset
dim sql as string

sql = "USE master; SELECT NAME FROM sysdatabases"
set rs = consource.execute(sql,,1)

do while not rs.eof
'rs(0) will be the current NAME, do whatever you want with it
rs.movenext
loop
 
Back
Top