Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Running sql stored procedures from Excel

I am trying to right a simple front-end in VBA for Excel to return results
from SQL stored procedures after the user selects the input variable values
from a multi-select list box.

I did something similar out of Access last year; but all the ADODB. syntax
doesn't work in Excel VBA. (I've figured out the differences between Access
and Excel with the list box properties but not with the connection, query,
parameters... )

Provided below is my Access VBA code; how do I need to modify to run out of
Excel?

I am running Access 2002 and Excel 2002.


Private Sub lst_user_DblClick(Cancel As Integer)

'Get user-selected value for stored procedure parameter

For j = 0 To lst_user.ListCount - 1
If lst_user.Selected(j) = True Then
var1 = lst_user.ItemData(j)
End If
Next j

Dim cnn1 As ADODB.Connection
Dim runspcmd As ADODB.Command
Dim runempty As ADODB.Command
Dim runsp_param As ADODB.Parameter
Dim intvar As Integer
Dim strCnn As String

Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "Provider=SQLOLEDB;driver={SQL
Server};Server=(local);Initial Catalog=excelsqltest;
userid=myname;Password=;Trusted_Connection=Yes"
cnn1.Open strCnn

' Open command object with one parameter.
Set runspcmd = New ADODB.Command
runspcmd.CommandText = "sp_testproc"
runspcmd.CommandType = adCmdStoredProc


' Get parameter value and append parameter.
intvar = var1
Set runsp_param = runspcmd.CreateParameter("recno", _
adInteger, adParamInput)
runspcmd.Parameters.Append runsp_param
runsp_param.Value = intvar


' execute the command.
Set runspcmd.ActiveConnection = cnn1
runspcmd.Execute

cnn1.Close

DoCmd.Close acForm, Form.Name
DoCmd.OpenReport "outputtable", acViewPreview

end sub
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
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
Stop excel from dropping the 0 in the beginning of a number? Rosewood Setting up and Configuration of Excel 12 April 4th 23 02:12 PM
Convert numbers stored as text to numbers Excel 2000 Darlene Excel Discussion (Misc queries) 6 January 31st 06 08:04 PM
I am running Excel 2003 from Office 2003 Professional Tillso Excel Discussion (Misc queries) 1 October 21st 05 03:27 PM
Excel files on local drives running from internet FillyFriend Excel Worksheet Functions 0 November 22nd 04 09:23 PM


All times are GMT +1. The time now is 01:20 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"