I have a stored procedure in MS SQL 2005 and want to create a recordset in Access 2007 VBA from a stored procedure that accepts input for data range for records to be included in the recordset.
The following line works in Management Studio Query window when executed:
EXEC [dbo].[EZ-2000] '1/15/2011','1/30/2011'
I run the code below and it seems to spend some time running the SP but the recordset does not return any records.
Any help/ideas?
-- ealier code to define SP input dates ---
Dim StartDate As Date
Dim EndDate As Date
-- Start and End dates are taken from Access form --
StartDate = CDate(Me.Date_Billed_From_Date)
EndDate = CDate(Me.Date_Billed_To_Date)
-- When I debug, these dates show up as same dates I use in Query above --
--- main code ----
Dim Cmd1 As New ADODB.Command
Dim rs As New ADODB.Recordset
' On Error GoTo Err_CompcareExcel_Click
Set Cmd1 = New ADODB.Command
Cmd1.ActiveConnection = "Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;Integrated Security=SSPI;"
Cmd1.CommandText = "[dbo].[EZ-2000]"
Cmd1.CommandType = adCmdStoredProc
-- I tried this line without the above 2 lines and next 3 and same results --
'Cmd1.CommandText = "EXEC [dbo].[EZ-2000] '1/15/2011','1/30/2011'"
-- I used the next line to verify that connection to server is fine and it did return a recordset ---
'Cmd1.CommandText = "SELECT * FROM Known_Table"
Cmd1.Parameters.Refresh
Cmd1.Parameters("@BegDate").Value = StartDate
Cmd1.Parameters("@EndDate").Value = EndDate
Set rs = Cmd1.Execute()
rs.Open Cmd1
--- above code runs for a while and any later code that tries to extract data from rs results in error message that rs is not open ---