Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? | Excel Discussion (Misc queries) | |||
Stop excel from dropping the 0 in the beginning of a number? | Setting up and Configuration of Excel | |||
Convert numbers stored as text to numbers Excel 2000 | Excel Discussion (Misc queries) | |||
I am running Excel 2003 from Office 2003 Professional | Excel Discussion (Misc queries) | |||
Excel files on local drives running from internet | Excel Worksheet Functions |