G
Guest
One problem I worked through was setting the command
values to numbers. example
objCmd.CommandType = 4 - instead of adCmdStoredProc...
The stored proc runs, but I can't open the recordset.
I tried all options.
The recordset state is always = 0
I now the record count from the Execute matches.
<operation is not allowed when the object is closed>
Appreciative of help. Jeff
Public Sub ExecProc150()
Dim DateStr As Date
DateStr = #3/1/2004#
Dim szConnect As String
szConnect = "Provider=SQLOLEDB;Data Source=Server;" & _
"Initial Catalog=Database;Integrated
Security=SSPI"
Dim Conn As Object
Set Conn = CreateObject("ADODB.Connection")
Conn.Open szConnect
Dim objCmd As Object
Set objCmd = CreateObject("ADODB.Command")
objCmd.CommandText = "AMTexcelProjJWRTest550"
objCmd.CommandType = 4
Set objCmd.activeconnection = Conn
Application.ODBCTimeout = 0
Dim objParam As Object
Set objParam = CreateObject("ADODB.Parameter")
Set objParam = objCmd.CreateParameter
("@ForecastBeginDate", 133, 1, 8, CDate(DateStr))
objCmd.Parameters.Append objParam
Dim rsData As Object
Set rsData = CreateObject("ADODB.RecordSet")
Set rsData.activeconnection = Conn
rsData.cursortype = 1
rsData.locktype = 2
rsData.CursorLocation = 1
Set rsData = objCmd.Execute(AMT, objParam)
Set rsData.Source = objCmd
rsData.Open objCmd
testState = rsData.State
If Not rsData.EOF Then
' Dump the contents of the recordset onto the
worksheet.
Sheet1.Range("A1").CopyFromRecordset rsData
' Close the recordset
rsData.Close
' Fit the column widths to the data.
Sheet1.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: No records returned.", vbCritical
End If
' Clean up our ADO objects.
If CBool(objConn.State And adStateOpen) Then Conn.Close
Set Conn = Nothing
If CBool(rsData.State And adStateOpen) Then
rsData.Close
Set rsData = Nothing
End Sub
values to numbers. example
objCmd.CommandType = 4 - instead of adCmdStoredProc...
The stored proc runs, but I can't open the recordset.
I tried all options.
The recordset state is always = 0
I now the record count from the Execute matches.
<operation is not allowed when the object is closed>
Appreciative of help. Jeff
Public Sub ExecProc150()
Dim DateStr As Date
DateStr = #3/1/2004#
Dim szConnect As String
szConnect = "Provider=SQLOLEDB;Data Source=Server;" & _
"Initial Catalog=Database;Integrated
Security=SSPI"
Dim Conn As Object
Set Conn = CreateObject("ADODB.Connection")
Conn.Open szConnect
Dim objCmd As Object
Set objCmd = CreateObject("ADODB.Command")
objCmd.CommandText = "AMTexcelProjJWRTest550"
objCmd.CommandType = 4
Set objCmd.activeconnection = Conn
Application.ODBCTimeout = 0
Dim objParam As Object
Set objParam = CreateObject("ADODB.Parameter")
Set objParam = objCmd.CreateParameter
("@ForecastBeginDate", 133, 1, 8, CDate(DateStr))
objCmd.Parameters.Append objParam
Dim rsData As Object
Set rsData = CreateObject("ADODB.RecordSet")
Set rsData.activeconnection = Conn
rsData.cursortype = 1
rsData.locktype = 2
rsData.CursorLocation = 1
Set rsData = objCmd.Execute(AMT, objParam)
Set rsData.Source = objCmd
rsData.Open objCmd
testState = rsData.State
If Not rsData.EOF Then
' Dump the contents of the recordset onto the
worksheet.
Sheet1.Range("A1").CopyFromRecordset rsData
' Close the recordset
rsData.Close
' Fit the column widths to the data.
Sheet1.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: No records returned.", vbCritical
End If
' Clean up our ADO objects.
If CBool(objConn.State And adStateOpen) Then Conn.Close
Set Conn = Nothing
If CBool(rsData.State And adStateOpen) Then
rsData.Close
Set rsData = Nothing
End Sub