473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Testing for an open recordset

I ran into problems in an app in which I received a msg of "cannot lock the
table, it is in use by another user". It turns out that I had opened a
recordset with a command like set rstmyrecs = openrecordset("Tablename") to
get a record count and I was trying to run a query to modify the table even
though I had not yet closed the recorset.

I fixed most of them, but I was wondering if there is a way to test if a
recorset is open. I got hit with the same error msg the other day and I
realized that while my code released the recordset variable from memory
(rstmyrecs = nothing), it did not close it. I seem to recall getting an
error msg if I tried to close a recorset that was not open or whose variable
was already released from memory (cannot recall which).

Anyhow, I'd like to be able to test to see if the recordset is open to do
something like

If recordset rstmyrecs is open then
rstmyrecs.close
end if

Is there such a command or some other way to achieve the same thing?
Thanks
Nov 13 '05 #1
2 6682
You can test to see if the variable is set

If rst = Nothing Then

but to catch the other, when you try to Close the recordset, the easiest
thing to do is to just trap the error. Unless you are doing something that
specifically would require otherwise, it is usually easiest to use a two
command statement as if it is a single command.

rst.Close
Set rst = Nothing

--
Wayne Morgan
MS Access MVP
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:_VOOc.63586$eM2.49687@attbi_s51...
I ran into problems in an app in which I received a msg of "cannot lock the table, it is in use by another user". It turns out that I had opened a
recordset with a command like set rstmyrecs = openrecordset("Tablename") to get a record count and I was trying to run a query to modify the table even though I had not yet closed the recorset.

I fixed most of them, but I was wondering if there is a way to test if a
recorset is open. I got hit with the same error msg the other day and I
realized that while my code released the recordset variable from memory
(rstmyrecs = nothing), it did not close it. I seem to recall getting an
error msg if I tried to close a recorset that was not open or whose variable was already released from memory (cannot recall which).

Anyhow, I'd like to be able to test to see if the recordset is open to do
something like

If recordset rstmyrecs is open then
rstmyrecs.close
end if

Is there such a command or some other way to achieve the same thing?
Thanks

Nov 13 '05 #2
Colleyville Alan wrote:
I ran into problems in an app in which I received a msg of "cannot lock the
table, it is in use by another user". It turns out that I had opened a
recordset with a command like set rstmyrecs = openrecordset("Tablename") to
get a record count and I was trying to run a query to modify the table even
though I had not yet closed the recorset.

I fixed most of them, but I was wondering if there is a way to test if a
recorset is open. I got hit with the same error msg the other day and I
realized that while my code released the recordset variable from memory
(rstmyrecs = nothing), it did not close it. I seem to recall getting an
error msg if I tried to close a recorset that was not open or whose variable
was already released from memory (cannot recall which).

Anyhow, I'd like to be able to test to see if the recordset is open to do
something like

If recordset rstmyrecs is open then
rstmyrecs.close
end if

Is there such a command or some other way to achieve the same thing?
Thanks


Not in DAO (you could set a flag when you open the recordset and then test the
flag to determine whether to close it.

ADO Recordsets have a .State property that is set to adStateOpen (1) when open.

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ImraneA | last post by:
Hi there I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K. Wish to provide some knowledge gained back to community - hopefully help others. 1.Question how do you test stored...
4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
2
by: Sunil Korah | last post by:
I am having some trouble with opening recordsets. I have used code more or less straight from the access help. But still I am getting some errors. I am unable to work out what exactly I am doing...
2
by: PeterW | last post by:
I have a data entry form based on a query. As a user enters data in the fields, I want to check if that data exists in the underlying table. I have tried Dlookup on the table and also a...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
0
ADezii
by: ADezii | last post by:
When you create a Recordset, you may want to know immediately whether that Recordset actually contains any Rows. There are Recordsets that don't return any Rows and you may need to take different...
8
by: metalheadstorm | last post by:
ok ive set up a connection between my access db ( 97) and my vb6 interface and this is what i got form_load Data6.DatabaseName = App.Path & "\cjmillers.mdb" Data6.RecordSource = "select * from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.