-
ADO
How come I couldn't open it the second time?
THese are my code:
'I open the connection and myTable fisrt time:
With DataEnvironment1.cnnVendor
.ConnectionString = "Persist Security Info=False;User ID=Admin;" & _
"Data Source=" & MyDatabaseName & ";"
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = adModeReadWrite
.Open
End With
DataEnvironment1.rsMyTable.Open
end with
'I close my connection and myTable:
DataEnvironment1.rsMyTable.close
DataEnvironment1.cnnVendor.close
'I open the connection and myTable second time (exactly the same code!!!)
With DataEnvironment1.cnnVendor
.ConnectionString = "Persist Security Info=False;User ID=Admin;" & _
"Data Source=" & MyDatabaseName & ";"
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = adModeReadWrite
.Open
End With
DataEnvironment1.rsMyTable.Open
end with
---> but the last line "DataEnvironment1.rsMyTable.Open" bomb ???
The error say :"operation on an object with a reference to a closed or invalid Connection object."
Please help me out.
Thanks
-
Re: ADO
Kathy,
Are you looping through tables, or is this the exact same table object? If your looping through tables you might need to set the table object = Nothing after closing it, and then Set it again at the top of the loop.
-
Re: ADO
It's exacly the same table, and even if I set table record set to nothing,
still I've got the same error
-
Re: ADO
I've found code to help when you get the error you mentioned.
If DataEnvironment1.cnnVendor.State = adStateClosed then
DataEnvironment1.cnnVendor.Open
End If
-- Adding these few lines of code before you get the error should prevent your problem. This has worked for me and hopefully it helps your problem. If not then I'm sorry I don't know what to tell you.