Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL to EXCEL ???

Status
Not open for further replies.

ssecca

Programmer
Feb 13, 2002
219
US
I desire to import a table (SQL query) directly from SQL 2000 database to an excel spreadsheet. I must be missing something here. Does any have a simple code sample that would allow me to see what I'm missing. I do not seem to be able to get the connection working correctly.

<CODE FOLLOWS>
Dim dbs As Database
Dim qry As QueryDef
Dim rst As Recordset

dbs.Connect = "ODBC;DSN=LOCAL;UID=sa;PWD=target;DATABASE=contact"
Set qry = dbs.CreateQueryDef("myNAmes", "select * from dbo_C_tbl_Contacts")
Set rst = qry.OpenRecordset()
[A2].CopyFromRecordset rst

<END CODE>

I don't seem to be able to set the database in this example. Any help much welcomed. Thanks
 
Your declaration of "dbs" simply declares "dbs" to be an object of type "Database" but it doesn't actually create the object. You need
[tt]
Set dbs = New Database
[/tt]

to instantiate the "dbs" object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top