View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
NateBuckley NateBuckley is offline
external usenet poster
 
Posts: 146
Default Closing a recordset error : Operation is not allowed when...is clo

Hello, I've been playing around with connecting to a database and inserting
information using the following code. (just pasting it in sorry if it looks
messy)

Sub ADOTest()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\temp\testdb\test.mdb;"
cn.CursorLocation = adUseClient
strSQL = "INSERT INTO tblPeople ([fldName], [fldAge]) VALUES('A Test',
'24');"

rs.Open strSQL, cn

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

I get the following error on the line that says "rs.Close"

"Operation is not allowed when the object is closed. "

It was to my understanding that I had to close everything, it inserts the
test data and continue to works if i comment out that line, but I'd like to
know why it isn't working.

Thanks for any help