I have set up a connection to my SQL server to the database where the stored procedure is located. The Stored Procedure works fine in SQLServer. The Stored Procedure runs
Sub Samp()
Public con As New ADODB.Connection
Public PassRecordset As New ADODB.Recordset
Public objCmd As New ADODB.Command
Dim Para1 As ADODB.Parameter
Dim Para2 As ADODB.Parameter
Dim Para3 As ADODB.Parameter
'Check the database connection
If con.State = 0 Then If Not CreateConnection
Then Exit Sub
Set objCmd = New ADODB.Command
objCmd.ActiveConnection = con
With objCmd
.ActiveConnection = con
.CommandType = adCmdStoredProc
.CommandText = StoredProcedureName
End With
Set Para1 = objCmd.CreateParameter("@TextPara1", adVarChar, adParamInput, 50, "Value1")
objCmd.Parameters.Append Para1
Set Para2 = objCmd.CreateParameter("@TextPara2", adVarChar, adParamInput, 255, "Value2")
objCmd.Parameters.Append Para2
Set Para3 = objCmd.CreateParameter("@DatePara3", adDate, adParamInput, , "DateValue")
objCmd.Parameters.Append Para3
Set PassRecordset = objCmd.Execute
Sheet1.Range("A1").CopyFromRecordset PassRecordset
End Sub