Click to See Complete Forum and Search --> : ADO


Kathy
January 27th, 2000, 10:35 AM
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

jhemphill
January 27th, 2000, 11:02 AM
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.

Kathy
January 27th, 2000, 12:18 PM
It's exacly the same table, and even if I set table record set to nothing,
still I've got the same error

January 27th, 2000, 04:20 PM
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.