Run a Stored Procedure from Excel
- From: Jez <Jez@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 19 Sep 2008 04:04:01 -0700
I have this code below to Execute a Command in Stored Procedure in SQL
Server. My problem is that I keep having an error message saying
Error: Operation is not allowed when the object is closed. 3704
I have no idea what that means,
Option Explicit
Dim cnnDW As ADODB.Connection
Dim rsDW As ADODB.Recordset
'Dim cnnSP As ADODB.Command
Dim sQRY As String
Dim strDWFilePath As String
Sub GetData()
On Error GoTo Err:
strDWFilePath = "Driver={SQL Native
Client};Server=CISSQL1;Database=CORPINFO;Trusted_Connection=Yes"
Set cnnDW = New ADODB.Connection
Application.ScreenUpdating = False
cnnDW.Open strDWFilePath
Sheet1.Range("E4:F9").ClearContents
Set rsDW = New ADODB.Recordset
sQRY = "DECLARE @wlvals varchar(100) " & _
"SET @wlvals = char(39) + 'T2DEA' + char(39) + ',' +
char(39) + 'T2DEP' + char(39) " & _
"EXEC sp_WLName_Report 'September', '2008', '18-09-2008',
@wlvals"
rsDW.CursorLocation = adUseClient
rsDW.Open sQRY, cnnDW, adOpenDynamic, adLockOptimistic, adCmdText
Application.ScreenUpdating = False
Sheet1.Range("E4").CopyFromRecordset rsDW
rsDW.Close
Set rsDW = Nothing
MsgBox "Import Complete", vbInformation, "SQL Connection"
cnnDW.Close
Set cnnDW = Nothing
Exit Sub
Err:
MsgBox "The following error has occured-" & vbCrLf & vbCrLf & VBA.Error,
vbCritical, "SQL Connection"
MsgBox VBA.Err
End Sub
Where am I going wrong?
.
- Follow-Ups:
- RE: Run a Stored Procedure from Excel
- From: Joel
- RE: Run a Stored Procedure from Excel
- Prev by Date: RE: Calling a public function from a work***
- Next by Date: RE: Pick data from web page (no query)
- Previous by thread: Are there any other way to run the vba code than...
- Next by thread: RE: Run a Stored Procedure from Excel
- Index(es):
Loading