PDA

View Full Version : How to get populate a EXCEL table from an SQL server ?


ontheDB
09-24-03, 13:07
Hi,

How would you populate a table from an sql server ?

I'm not that familiar w/ Excel,

Where would I put my connection/SQL statements ?


e.g.

Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
Set cn = CreateObject("ADODB.Connection")
cn.Provider = "SQLOLEDB"
cn.ConnectionString = "server=blah;database=blah;uid=blah;pwd=blah"
cn.ConnectionTimeout = 600
cn.Open

ontheDB
09-24-03, 14:13
Originally posted by ontheDB
Hi,

How would you populate a table from an sql server ?

I'm not that familiar w/ Excel,

Where would I put my connection/SQL statements ?


e.g.

Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
Set cn = CreateObject("ADODB.Connection")
cn.Provider = "SQLOLEDB"
cn.ConnectionString = "server=blah;database=blah;uid=blah;pwd=blah"
cn.ConnectionTimeout = 600
cn.Open

I want to automate a query, so that I can run it with the push of a button.
Is this as easy as I suspect ?
I start recording of a Macro
I just go to
DATA -> Get External Data - > New Database Query
enter my SQL 'select' statements.
and populate the corresponding Excel sheets.
And stop the recording of a Macro .