#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default SQL Query

Please,
I need sample of VBA code of the best way to:
1) do a SQL connection from Excel
2) Execute a query statement that returns the result to a cell.

thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default SQL Query

Bret wrote...
I need sample of VBA code of the best way to:
1) do a SQL connection from Excel
2) Execute a query statement that returns the result to a cell.


Why not use the SQL.REQUEST add-in function?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default SQL Query


Bret wrote:
I need sample of VBA code of the best way to:
1) do a SQL connection from Excel
2) Execute a query statement that returns the result to a cell.


Sub test()
Dim rs As Object
Set rs = CreateObject("ADODB.Recordset")
rs.Open _
"SELECT CompanyName FROM Customers", _
"Provider=SQLOLEDB.1;Data Source=(local);" & _
"Initial Catalog=Northwind;" & _
"User Id=sa;Password=;"
Sheet1.Range("A1").CopyFromRecordset rs
End Sub

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert hard coded query criteria to Parameter Query Melanie[_2_] Excel Discussion (Misc queries) 0 July 15th 08 09:59 PM
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Save data retreived from query without saving query Anthony Excel Discussion (Misc queries) 0 January 25th 06 07:17 PM
Stop to modify the SQL query manually entered into query ! Olivier Rollet Excel Programming 6 November 3rd 04 08:34 AM
Problem with .Background Query option of ODBC Query Shilps Excel Programming 0 April 19th 04 06:41 AM


All times are GMT +1. The time now is 01:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"