jobu171980
IS-IT--Management
I am trying to set a form's recordset to a recordset returned from a stored procedure in SQL. And I am getting the error "The object you entered is not a valid Recordset property."
Any help will be gladly appreciated.
I am using Access 2010.
Private Sub Form_Open(Cancel As Integer)
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim stSQL As String
stSQL = "EXEC StoredProcedure " & Forms("Form1").Text0
Const stADO As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=Database;" & _
"Data Source=SQLServer"
Set con = New ADODB.Connection
With con
.Open stADO
.CommandTimeout = 0
Set rs = .Execute(stSQL)
End With
Set Me.Recordset = rs
Exit_FormOpen:
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
Exit Sub
Error_FormOpen:
MsgBox Err.Description, vbCritical
Resume Exit_FormOpen
End Sub
Any help will be gladly appreciated.
I am using Access 2010.
Private Sub Form_Open(Cancel As Integer)
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim stSQL As String
stSQL = "EXEC StoredProcedure " & Forms("Form1").Text0
Const stADO As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=Database;" & _
"Data Source=SQLServer"
Set con = New ADODB.Connection
With con
.Open stADO
.CommandTimeout = 0
Set rs = .Execute(stSQL)
End With
Set Me.Recordset = rs
Exit_FormOpen:
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
Exit Sub
Error_FormOpen:
MsgBox Err.Description, vbCritical
Resume Exit_FormOpen
End Sub