473,379 Members | 1,222 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,379 software developers and data experts.

what condition will determine whether a recordset is currently open?

i'm having problem in closing my recordset while it is used in many purposes..

if i'd only knew a condition that would help me determine whether a current recordset is open.. it would help me a lot...
Jul 14 '12 #1
2 1500
twinnyfo
3,653 Expert Mod 2GB
aquinori,

You are kind of stuck between a rock and a hard place. First, there is no condition or property for a recordset that will indicate whether or not it is open, because if it is open, there it is, if it is closed, any action taken on that recordset will generate an error.

You may be able to trap the error before your code stops, however. For example, VBA will give error number 3420 of you try to do something with a recordset that is closed. In such a case, you test for that error, and if so, tell the code to resume where it left off (or notify you of the error and just stop without breaking anything).

However, the best advice I can give is to manage your recordsets very carefully. You should never close your recordset until you are sure you will never use it again in the particular sub or function. Additionally, although this is not a recommended practice, your code will respond better to a recordset left open (or just ignored) than one which is closed and then some action taken on it.

It's a good practice to wait until the end of a sub (or a particular loop) to close your recordsets or set them to nothing. This will free up memory, too.

Not sure if I really "answered" your question, but this info might help. Without seeing any of the code you have in question, we can't fix any particulars......
Aug 21 '12 #2
Killer42
8,435 Expert 8TB
One handy technique is to create a global variable corresponding to each recordset - let's say a Boolean "flag" variable. When you open the recordset, set the flag to True. When you close it (after testing the flag to see whether it's open) you set the flag to False. Any process that needs to know can now check that flag to see whether the recordset is open.

Another way to manage multiple processes which may want to access a common recordset is to use a counter rather than a simple flag. Each time you want to open the recordset, add 1 to the counter. Open the recordset only if the counter now = 1 (otherwise, it's already open). Likewise, each time a process is finished with the recordset, subtract 1 from the counter. When it hits 0, close. As long as that counter is > 0 you know the recordset's available for use.

You may come up with some other scheme yourself - don't be afraid to make up your own "attributes". :-)
Aug 22 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: OvErboRed | last post by:
Hi, I'm trying to determine whether a given URL exists. I'm new to Python but I think that urllib is the tool for the job. However, if I give it a non-existent file, it simply returns the 404 page....
1
by: Ashabul Yeameen | last post by:
I am writing a program which at some point need to call fputwc() function. But since I want to make this code portable I've decided to write my own fputwc() funcion where the compiler doesn't...
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? ...
1
by: topramen | last post by:
does any one here know of a good way to to determine whether or not a given path is a directory (e.g., "c:\mydir") or a file (e.g., "c:\mydir \myfile.txt")? i started attacking this problem by...
9
by: Mark Berry | last post by:
Hi, How can I determine whether an object is derived from another object? My specific example is that I have a CustomError class with several specific error types that derive from it...
3
by: abhimanyu | last post by:
I have a method Marshal.IsComObject(...) that returns TRUE if an object is a COM object. I have an object of Excel.Worksheet that I released using Marshal.ReleaseComObject(...). I want to iterate...
4
by: vinod allapu | last post by:
hi all, I have a aspx page which can be opened directly or it can be opened from other aspx page using javascript window.open .... now i need to check whether it is open from a parent...
6
by: jtgarrison | last post by:
Is there a way to tell if Outlook is open before sending a message and open it if it's not? I have some old code that I have been using: 'Determine If Outlook Is Open. If Not, Open. Set...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.