Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to access MSSQL table in a user defined function

Hi

I would appreciate if someone could help me with some sample code that
I can use in my custom function to access a ODBC database and send a
SQL statement to retrieve data from a table.

BTW, how can I store the ADO recordset in a array so that my VBA
function can manipulate?

Your advice most appreciated. Thanks

Best Regards

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to access MSSQL table in a user defined function

Sub GetData()
Dim rst As New Recordset
Dim SQLcmd As String

Cells.Select
Cells.Delete

'Using northwind as example

SQLcmd = "Select * from Customers"
'If running a Stored Procedure SQLcmd = "Execute MyStoredProcedureName"

rst.Open Source:=SQLcmd,
ActiveConnection:="Provider=Microsoft.Jet.OLEDB.4. 0; Data Source=C:\Program
Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;"
'For SQL ODBC use the following Active Connection

'Driver={SQLServer};Server=Your_Server_Name;Databa se=Your_Database_Name;Uid=Your_Username;Pwd=Your_P assword;

'This copies the data directly to the spreadsheet
Range("A1").CopyFromRecordset rst

End Sub

" wrote:

Hi

I would appreciate if someone could help me with some sample code that
I can use in my custom function to access a ODBC database and send a
SQL statement to retrieve data from a table.

BTW, how can I store the ADO recordset in a array so that my VBA
function can manipulate?

Your advice most appreciated. Thanks

Best Regards


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
User defined function linzhang426 New Users to Excel 4 October 10th 05 03:18 PM
Access connection works in Macro, not in user-defined Function Steve[_77_] Excel Programming 3 May 27th 05 02:07 PM
User defined function PC[_3_] Excel Programming 1 August 17th 04 04:58 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 11:47 PM.

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

About Us

"It's about Microsoft Excel"