473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

openrecordset without using "set variable = "

I recently discovered that you can do the following:

if currentdb.openrecordset ("select statement.....").eof = true then

for cases when you just want to see if any records exist.

This obviously does not assign the recordset to any variable. My
question is, does this still use memory that is not freed because
there is no "recset.close" and "set variable = nothing"?
Nov 12 '05 #1
2 2267
On 6 Feb 2004 07:59:27 -0800, ka***@regardingbooks.com (K Williams) wrote:
I recently discovered that you can do the following:

if currentdb.openrecordset ("select statement.....").eof = true then

for cases when you just want to see if any records exist.

This obviously does not assign the recordset to any variable. My
question is, does this still use memory that is not freed because
there is no "recset.close" and "set variable = nothing"?


To be safe, you should not assume this is OK. You could certainly write a
function to do that for you the right way, though, so the code everywhere else
is just as simple.

Oh, and I have found .EOF to be unreliable for checking if records were
returned in a DAO Recordset. RecordCount, though unreliable as a count prior
to .MoveLast is accurate for determining whether zero or >=1 records were
returned. This kind of thing is another good reason for centralizing this
sort of code. If you find a bug in your approach, or you come up with a
performance improvement, etc. you can fix it in just one place to handle
everywhere it's used.

Here's some air code (could use some error handling)...

Public Function DoesRecordExist( _
strSQL As String, _
Optional dbs As DAO.Database _
) As Boolean
Dim blnLocalDbs As Boolean
Dim rst As DAO.Recordset

If dbs Is Nothing Then
Set dbs = CurrentDB()
blnLocalDbs = True
End If

Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardonly)
DoesRecordExist = (rst.RecordCount > 0)

rst.Close: Set rst = Nothing

If blnLocalDbs Then set dbs = Nothing

End Function
Nov 12 '05 #2
Thanks, Steve. That's good advice.

Steve Jorgensen <no****@nospam.nospam> wrote in message news:<de********************************@4ax.com>. ..
On 6 Feb 2004 07:59:27 -0800, ka***@regardingbooks.com (K Williams) wrote:
I recently discovered that you can do the following:

if currentdb.openrecordset ("select statement.....").eof = true then

for cases when you just want to see if any records exist.

This obviously does not assign the recordset to any variable. My
question is, does this still use memory that is not freed because
there is no "recset.close" and "set variable = nothing"?


To be safe, you should not assume this is OK. You could certainly write a
function to do that for you the right way, though, so the code everywhere else
is just as simple.

Oh, and I have found .EOF to be unreliable for checking if records were
returned in a DAO Recordset. RecordCount, though unreliable as a count prior
to .MoveLast is accurate for determining whether zero or >=1 records were
returned. This kind of thing is another good reason for centralizing this
sort of code. If you find a bug in your approach, or you come up with a
performance improvement, etc. you can fix it in just one place to handle
everywhere it's used.

Here's some air code (could use some error handling)...

Public Function DoesRecordExist( _
strSQL As String, _
Optional dbs As DAO.Database _
) As Boolean
Dim blnLocalDbs As Boolean
Dim rst As DAO.Recordset

If dbs Is Nothing Then
Set dbs = CurrentDB()
blnLocalDbs = True
End If

Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardonly)
DoesRecordExist = (rst.RecordCount > 0)

rst.Close: Set rst = Nothing

If blnLocalDbs Then set dbs = Nothing

End Function

Nov 12 '05 #3

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

Similar topics

7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
2
by: MLH | last post by:
I copied the following code right out of MS Access 2.0 HELP under Index Property Setting example... Sub Button0_Click () Dim MyDB As Database, MyTable As Recordset Set MyDB =...
9
by: MLH | last post by:
A runtime error 13 (type mismatch) occurs running the following line: Set rst = dbs.OpenRecordset("tblMyTable", dbOpenTable) What would be the most likely place I would find the source of the...
1
by: kelvinweb | last post by:
Hi All, Is it possible to using variable store container.dataitem in ItemTemplate ?? For example. <ItemTemplate> <% Dim x x = container.dataitem("LineNo")
6
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
9
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There...
11
by: mfglinux | last post by:
Hello to everybody I would like to know how to declare in python a "variable name" that it is in turn a variable In bash shell I would wrote sthg like: for x in `seq 1 3` do M$i=Material(x)...
1
by: ragonz | last post by:
Hi, i'm kind of newbie in java programming. Now, i'm working on my task, n i hav a problem in using variable from other method. Here goes the code.. import java.awt.*; import java.awt.event.*;...
2
complete
by: complete | last post by:
What is the point of using set and get in C Sharp? It seems variables are used differently in this language than in C++. For some reason, you have to have a static variable defined like this:...
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...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.