I'm still trying to sort this problem...
The code below is where I am upto now. theres an error message now as below too, I cant see where I am going wrong??
Code:
Option Explicit
Dim cnnDW As ADODB.Connection
Dim rsDW As ADODB.Recordset
Dim cmdSP As ADODB.Command
Dim strDWFilePath As String
Dim stProcName As String
Sub GetData()
strDWFilePath = "Driver={SQL Native
Client};Server=CISSQL1;Database=CORPINFO;Trusted_Connection=Yes"
Set cnnDW = New ADODB.Connection
Application.ScreenUpdating = False
cnnDW.Open strDWFilePath
Set cmdSP = New ADODB.Command
Set rsDW = New ADODB.Recordset
stProcName = "DECLARE @wlvals varchar(100) " & _
"SET @wlvals = char(34)
+ 'T2DEA' + char(34) + ',' + char(34) + 'T2DEP' + char(34);" & _
"EXEC sp_WLName_Report
'September', '2008', '18-09-2008', @wlvals" 'Define name of Stored Procedure
to execute."
cmdSP.CommandType = adCmdStoredProc 'Define the ADODB command
cmdSP.ActiveConnection = cnnDW 'Set the command connection string
cmdSP.CommandText = stProcName 'Define Stored Procedure to run
Sheet1.Range("E4:F9").ClearContents
rsDW.Open cmdSP.Execute(stProcName)
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
End Sub
It now has moved my errror message from the Exec Statement to the line
below, but I am still baffled as to why it doesnt work...
Code:
rsDW.Open cmdSP.Execute(stProcName)
My Error message...
[Microsoft][SQL Native Client] Syntax Error, Permission Violation or Other
NonSpecific Error
Where am I going wrong?