Click to See Complete Forum and Search --> : rs.open or not
Patzer
August 27th, 2001, 06:35 AM
Hi out there,
How can I check if a recordset is open or closed? If I unload a form usually a recordset is still open, but on one occation it's closed.
The recordset is not nothing then.
Anybody got an Idea?
have a nice day,
Patzer
Cakkie
August 27th, 2001, 06:39 AM
For ADO, you can use the next code
If rst.state = adStateClosed then
Msgbox "Recordset is closed"
else
Msgbox "Recordset is open"
End If
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Patzer
August 27th, 2001, 07:41 AM
thanx a lot!!!
simple when you know how (as always in VB).
have a nice day,
Patzer
bhanuprakash
August 29th, 2001, 03:37 AM
you can use the state property of the recordset if the recordset is open the rs.state value will be 1 and if the recordset is closed the rs.state value will be 0.this will help you to determine whether the recordset is open or closed.
berta
August 29th, 2001, 03:43 AM
no.. it' not correct...
rs.state=0 then rs is closed...
bur rs.state=1 is not a correct test...
an rs can be in adStateOpen and adStateFetching ...so its state is 9...
the correct test is
'with reference
if rs.state and adstateopen then
'so i'm sure rs is open
end if
'without reference
if rs.state and 1 then
'so i'm sure rs is open
end if
hi,brt
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
Patzer
August 29th, 2001, 04:46 AM
Hi,
I have to admit that I do not really understand your idea so:
If a recordset.state returns true for adStateFetching at a time, does it also return true for adStateOpen at that time?
I mean there are also other states for the rs, as of adstateconnecting and adstateexecuting, so could you please give a little more Information on that?
thx´
have a nice day,
Patzer
berta
August 29th, 2001, 04:54 AM
the rs.state is a sum of state...
adStateClosed = 0 'bynary ->0000
adStateOpen = 1 'bynary ->0001
adStateConnecting = 2 'bynary ->0010
adStateExecuting = 4 '0100
adStateFetching = 8 '1000
if U want tio check state U must have a bynary check rs.state AND constant -> but it is a bad test when rs.state=adstateopen
so if (rs.state and adstateopen)=false then rs is closed...
exaple rs.state=adstateopen+adstateexecuting
so rs.state=5 -> 0101...
hi,btr
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
Patzer
August 30th, 2001, 06:57 AM
Hi Berta,
thx, took some time but then I understood (I think I did :-))
have a nice day,
Patzer
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.