tyndale2045
10-28-2008, 07:20 AM
[I screwed up and posted this question in the Excel section. And I can't figure out how to delete it. If any admin folk can delete it for me, or tell me how, that would be great. Anyways . . . to the question, now that I'm posting in the right place.]
I'm trying to learn SQL for a project I'm working on. In doing so, I've adapted the following code from the "Access 2002 Desktop Developer's Handbook." I have one question: don't I need to insert some kind of statement to close the ADO recordset? (I'm not using the DAO part of the code). But if I uncomment the rst.close line of code toward the bottom, I get this error "Operation is not allowed when the object is closed." So, what's the deal? How is it getting closed?
Any info will be appreciated.
Public Sub LearningSQL()
Dim intI As Integer
Dim strSQL As String
Dim sfm As SubForm
strSQL = "INSERT INTO [Inventory Transactions](ProductID, UnitsUsed) VALUES (6,676)"
#If USEDAO Then
' Open a DAO Recordset.
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)
#Else
' Open an ADO recordset.
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open Source:=strSQL, _
ActiveConnection:=CurrentProject.Connection, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnly, _
Options:=adCmdText
'rst.Close
#End If
End Sub
Thanks,
Jim
I'm trying to learn SQL for a project I'm working on. In doing so, I've adapted the following code from the "Access 2002 Desktop Developer's Handbook." I have one question: don't I need to insert some kind of statement to close the ADO recordset? (I'm not using the DAO part of the code). But if I uncomment the rst.close line of code toward the bottom, I get this error "Operation is not allowed when the object is closed." So, what's the deal? How is it getting closed?
Any info will be appreciated.
Public Sub LearningSQL()
Dim intI As Integer
Dim strSQL As String
Dim sfm As SubForm
strSQL = "INSERT INTO [Inventory Transactions](ProductID, UnitsUsed) VALUES (6,676)"
#If USEDAO Then
' Open a DAO Recordset.
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)
#Else
' Open an ADO recordset.
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open Source:=strSQL, _
ActiveConnection:=CurrentProject.Connection, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnly, _
Options:=adCmdText
'rst.Close
#End If
End Sub
Thanks,
Jim