473,686 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

do i need to set objects to nothing

Hi Folk

I have about 1000 procedures in my project. Many, many of them are along
the lines of

function myfuntion () as boolean
on error goto er
'-
Dim Dbs as dao.database
Dim Rst as dao.recordset
Dim SqlS as string
'-
sqls = "..."
set dbs = currentdb
set rst = dbs.openrecords et(sqls)
do while not rst.eof
.....
rst.movenext
loop
'-
xt:
exit function
er:
msgbox error$
resume xt
end function
Should set dbs and rst to nothing or is that not necessary. If so, does
anyone know of an easy way to update all my procedures at once?

TIA

- Nicolaas
Nov 13 '05
106 6432
"Mike MacSween" <mi************ *************** @btinternet.com > wrote
in news:42******** *************** @news.aaisp.net .uk:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .
If I were doing the code writing I would examine my code
carefully and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB


What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset


My guess is that what Lyle means is that if you're constantly
resetting a db variable to CurrentDB() you should either use
DBEngine(0)(0) directly, or use a persistent structure, either a
global variable storing a pointer to CurrentDB() or a function that
returns a reference to CurrentDB() drawn from a persistent variable.

I use the function posted after my signature. It has vastly
simplified my coding, as I never have to set a db variable just to
perform something using CurrentDB().

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Public Function dbLocal(Optiona l ysnInitialize As Boolean = True) _
As DAO.Database
' 2003/02/08 DWF added comments to explain it to myself!
' 2005/03/18 DWF changed to use Static variable instead
' of module Private variable for dbCurrent
' uses GoTos instead of If/Then because:
' error of dbCurrent not being Nothing but dbCurrent being closed
' would (3420)would then be jumping back into the middle of an
' If/Then statement
On Error GoTo errHandler
Static dbCurrent As DAO.Database
Dim strTest As String

If Not ysnInitialize Then GoTo closeDB

retryDB:
If dbCurrent Is Nothing Then
Set dbCurrent = CurrentDb()
End If
' now that we know the db variable is not Nothing,
' test if it's Open
strTest = dbCurrent.Name

exitRoutine:
Set dbLocal = dbCurrent
Exit Function

closeDB:
If Not (dbCurrent Is Nothing) Then
'dbCurrent.clos e
Set dbCurrent = Nothing
End If
GoTo exitRoutine

errHandler:
Select Case Err.Number
Case 3420 ' Object invalid or no longer set.
Set dbCurrent = Nothing
If ysnInitialize Then
Resume retryDB
Else
Resume closeDB
End If
Case Else
MsgBox Err.Number & ": " & Err.Description , _
vbExclamation, "dbLocal()"
Resume exitRoutine
End Select
End Function
Nov 13 '05 #21
On Sat, 14 May 2005 17:47:38 GMT, "David W. Fenton"
<dX********@bwa y.net.invalid> wrote:
Lyle Fairfield <ly******@yahoo .ca> wrote in
news:wt******* *********@read1 .cgocable.net:
IMO, while Access is a fine GUI, DAO and VBA are archaic, clumsy
and inefficient.


Well, from where I sit, technologies like ADO are so advanced and
up-to-date and sleekly designed that they guess what I mean to do
and end up getting results that are not what I would have intended.


That's somewhat true of ADO, but it's much more true of ADPs that happen to be
using ADO. ADO alone is not so bad, it's just that DAO is unavoidable anyway
in an Access application, so ADO is not a solution to resource problems in DAO
in Access.
Nov 13 '05 #22
Lyle Fairfield <ly******@yahoo .ca> wrote in
news:d7******** ********@read1. cgocable.net:
Mike MacSween wrote:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .

If I were doing the code writing I would examine my code
carefully and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB

What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset


hmmm ... It was late; I was recommending converting everything to
ADO. Therefore DAO references would be redundant.


A phenomentally idiotic recommendation if the back end is Jet.

Migrating to an inferior data access method (performance, features)
just to make coding slightly easier would be bloody stupid.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #23
On Sat, 14 May 2005 17:41:50 GMT, "David W. Fenton"
<dX********@bwa y.net.invalid> wrote:
Steve Jorgensen <no****@nospam. nospam> wrote in
news:dm******* *************** **********@4ax. com:
A
good rule of thumb is, put error handlers in your application
start-up routine and in every event handler. All other error
handling is optional (and to be avoided when as possible to keep
code simpler).


Er, I don't think you typed what you meant to type.


No, I meant to type "... and to be avoided when possible..." <g>.

I don't mean, of course, that you should just leave out handling where it's
needed to ensure graceful erorr handling. What I mean is that we should look
for ways of making sure errors will be handled gracefully with a minimum
number of error handling points, so the code consists, for the most part of
application logic, not cluttered by vast amounts of error handling baggage.

The minimum error handling required to make sure the user won't ever get an
error message directly from VB (which crashes Access run-time apps, by the
way) is what I said above. The start-up routine and every event handler needs
error handling, or it needs to contain a trivial call (no non-costant
parameter values) to a procedure that has error handling.
Nov 13 '05 #24
On Sat, 14 May 2005 17:53:10 GMT, "David W. Fenton"
<dX********@bwa y.net.invalid> wrote:
"Mike MacSween" <mi************ *************** @btinternet.com > wrote
in news:42******** *************** @news.aaisp.net .uk:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .
If I were doing the code writing I would examine my code
carefully and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB


What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset


My guess is that what Lyle means is that if you're constantly
resetting a db variable to CurrentDB() you should either use
DBEngine(0)( 0) directly, or use a persistent structure, either a
global variable storing a pointer to CurrentDB() or a function that
returns a reference to CurrentDB() drawn from a persistent variable.

I use the function posted after my signature. It has vastly
simplified my coding, as I never have to set a db variable just to
perform something using CurrentDB().


I call that a lazy initializer and I use them a lot, too. Another thing I
like to use them for is creating structures that hold application settings
read from a table or .ini file.
Nov 13 '05 #25
rkc
Trevor Best wrote:
Mike MacSween wrote:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .

If I were doing the code writing I would examine my code carefully
and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB


What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset

That very quickly goes out of scope, the next line using rst will fail.


What goes out of scope on the next line?
The recordset goes out of scope when the method or object it was created
in goes out of scope, but surely not just the next line.

Nov 13 '05 #26
On Sat, 14 May 2005 18:38:27 GMT, rkc <rk*@rochester. yabba.dabba.do. rr.bomb>
wrote:
Trevor Best wrote:
Mike MacSween wrote:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .
If I were doing the code writing I would examine my code carefully
and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB

What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset

That very quickly goes out of scope, the next line using rst will fail.


What goes out of scope on the next line?
The recordset goes out of scope when the method or object it was created
in goes out of scope, but surely not just the next line.


CurrentDb returns a new instance of DAO.Database. Since there's no variable
holding a reference to that instance, it goes out of scope immediately after
the statement completes.
Nov 13 '05 #27
rkc wrote:
Trevor Best wrote:
Mike MacSween wrote:
"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .
If I were doing the code writing I would examine my code carefully
and write code to change it by

1. removing redundant DAO references eg. SET db=CurrentDB


What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset


That very quickly goes out of scope, the next line using rst will fail.

What goes out of scope on the next line?
The recordset goes out of scope when the method or object it was created
in goes out of scope, but surely not just the next line.


Try it, a recordset needs a database to hang off of, as Steve points out
CurrentDb goes out of scope so now your rst variable points at nothing
and you can no longer use it.

--
[Oo=w=oO]

Nov 13 '05 #28
Steve Jorgensen wrote:
To me, that's like saying we should make programmers deal with pointers
correctly because they may eventually have to code in C.
That's a ridicularse statement. There's a difference between having to
use something specific to another language and not being sloppy.
To me, any way a
language can get junk out of the way, so a program has, as much as possible,
just logic about the application and not about the system, that's a good
thing.


Would you ever use:

open "filename" for output as #1

then never close it?

--
[Oo=w=oO]

Nov 13 '05 #29
rkc
Trevor Best wrote:
rkc wrote:
Trevor Best wrote:
Mike MacSween wrote:

"Lyle Fairfield" <ly******@yahoo .ca> wrote in message
news:q0******** *********@read1 .cgocable.net.. .
> If I were doing the code writing I would examine my code carefully
> and write code to change it by
>
> 1. removing redundant DAO references eg. SET db=CurrentDB

What's the problem with that?

Is it meant to be something like:

rst = CurrentDB.openr ecordset


That very quickly goes out of scope, the next line using rst will fail.


What goes out of scope on the next line?
The recordset goes out of scope when the method or object it was
created in goes out of scope, but surely not just the next line.

Try it, a recordset needs a database to hang off of, as Steve points out
CurrentDb goes out of scope so now your rst variable points at nothing
and you can no longer use it.


I'm baffled.

This works.

Sub testCurrentDB()
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenR ecordset("emplo yees")

showRS rs

Set rs = Nothing
End Sub

Sub showRS(rs As DAO.Recordset)
With rs
If Not .EOF Then
Debug.Print .Fields(0)
Debug.Print .Fields(1)
Debug.Print .Fields(2)
End If
End With
End Sub



Nov 13 '05 #30

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

Similar topics

2
1930
by: Bobby | last post by:
Hello everyone I have a question. The school I am working for is in the beginning process of having a webpage that will direct students to download there homework and be able to view there info like test scores and etc(the homework and info page will reside on our webservers at the school on the local intranet network). Now what I need is a way for the students to go to a login page and when logging in will be automatically directed to...
2
1787
by: Lin Ma | last post by:
Hello, I have a general question. In my asp page, I have DB connection, Recordset, and some variables like dim name, conn, rs set conn = Server.CreateObject("ADODB.Connection") .... set rs= server.createObject("ADODB.Recordset")
16
2202
by: Joel Finkel | last post by:
Folks, I am confused as to how to implement the following solution. I have a series of processing steps, each of which contains similar features (forms, etc). Therefore, I create a base class, Step, and subclass from that for specific steps. The Step class has a method, Execute(), which can return either Success or Failure. I have a Step Driver, which instantiates the first Step, calls its Execute()
5
3785
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
18
2329
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before. Here's the scenario: We have a base class with all virtual functions. We'll call this the Animal class. We then make two classes Fish and Bird that both inherit from Animal. In the program, we have a single array of Animal pointers that will...
4
14908
by: Paul H | last post by:
A typical chunk of code...... Set db = CurrentDb Set rs = db.OpenRecordset("tblFoo") <Do some stuff here> 'How much of the stuff below do I need? 'Do I need to close the recordset? rs.Close
9
3940
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result - I have read every post out there and spent hours trying to figure out the problem with no success whatsoever - I have constrained the problem to one form however, and I think it's hiding somewhere in my code associated with this form, which is...
1
7106
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
167
8289
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
0
8517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9057
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8933
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8770
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8779
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7600
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5799
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2947
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 we have to send another system
3
1935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.