473,399 Members | 3,401 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,399 software developers and data experts.

Where is it safe to delete the querydef?

MLH
Consider the following...

With MyDB
Set qdfA = .CreateQueryDef("NewQry", "Select * From tblData Where_
[Field]=True;")
Set rstA = .OpenRecordset(qdfA, dbOpenSnapshot)
With rstA
.MoveFirst
Do Until rstA.EOF
...
Loop
.Close
End With
..QueryDefs.Delete qdfA.Name
..Close
End With

Should the deletion of the NewQry querydef object occur before or
after the last .Close?

__________________________________________________ ___
notes: Look for .QueryDefs.Delete qdfMarkedAddnlOwnerRecs.Name
in Sub cmdSaveVehicleRec_Click()
on frmVehicleEntryForm
__________________________________________________ ___

Mar 24 '06 #1
7 6203
MLH schreef:
Consider the following...

With MyDB
Set qdfA = .CreateQueryDef("NewQry", "Select * From tblData Where_
[Field]=True;")
Set rstA = .OpenRecordset(qdfA, dbOpenSnapshot)
With rstA
.MoveFirst
Do Until rstA.EOF
...
Loop
.Close
End With
.QueryDefs.Delete qdfA.Name
.Close
End With

Should the deletion of the NewQry querydef object occur before or
after the last .Close?


Before. But why not use a temporary query if you're going
to delete it anyway?

--
Paul
Mar 24 '06 #2
MLH
On Fri, 24 Mar 2006 20:34:12 +0100, "kaniest"
<ka*****@invalid.invalid> wrote:
Before. But why not use a temporary query if you're going
to delete it anyway?

I tried that, but I kept getting an error when running
OpenRecordset - See new thread entitled
"I'm doing something wrong with OpenRecordset???"
Mar 24 '06 #3
I would certainly delete it after I am done...just as you have. however,
creating and deleing query us going to cause file bloat, and their is
little, if any reason to create a query...

Why not use

dim strSql as string
dim rstA as dao.recordset

set strSql = "Select * From tblData Where Field = True"

set rstA = currentdb.openRecordset(strSql)

do until rstA.EOF
' do whatever with the one roecrd
rst.MoveNext
loop
rstA.close
set rstA = nothing

you can see how clean, and how little the amount of above code is...and, we
don't even have to create a query.. You don't really even have to create a
database object either.....
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Mar 24 '06 #4
MLH wrote:
Consider the following...


Why on EARTH are you using a query? Just use the openrecordset method
on a currentdb object. Your code is simply adding a lot of uselessness
if you're not saving the query for something else... rather like going
camping and building a whole house each time instead of just erecting a
tent! 8)

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Mar 24 '06 #5
MLH
Why on EARTH are you using a query? Just use the openrecordset method
on a currentdb object. Your code is simply adding a lot of uselessness
if you're not saving the query for something else... rather like going
camping and building a whole house each time instead of just erecting a
tent! 8)


I see your point. Had I created the query using the QBE grid, saved it
as a permanent query in the query tab of the database window, I could
have eliminated having to create it on the fly. Would that be a better
approach? I was hoping something I could do from within DAO would
eliminate the need to have a permanently saved query object.
Mar 25 '06 #6

"MLH" <CR**@NorthState.net> wrote in message
news:22********************************@4ax.com...
Why on EARTH are you using a query? Just use the openrecordset method
on a currentdb object. Your code is simply adding a lot of uselessness
if you're not saving the query for something else... rather like going
camping and building a whole house each time instead of just erecting a
tent! 8)


I see your point. Had I created the query using the QBE grid, saved it
as a permanent query in the query tab of the database window, I could
have eliminated having to create it on the fly. Would that be a better
approach? I was hoping something I could do from within DAO would
eliminate the need to have a permanently saved query object.


What was meant is that you can Open a Recordset just with the SQL string and the
database object. You don't need a QueryDef at all. Then there is no need to
delete it.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Mar 25 '06 #7
MLH
What was meant is that you can Open a Recordset just with the SQL string and the
database object. You don't need a QueryDef at all. Then there is no need to
delete it.

I finally go that through my thick head. I made the modification and
you're absolutely right. Well, that's what I get for doing cut 'n
paste code snippets from A97 HELP w/o scrutinizing them.
Quite often they do say "... now delete the saved query since
this is just an example..." or something to that effect. I just
haven't been paying attention closely enough when snatching
the snippets.
Mar 26 '06 #8

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

Similar topics

2
by: qazmlp | last post by:
Say, ptr=0 / ptr=NULL. delete ptr; //is safe // Is delete ptr; // also safe ?
10
by: solosnake | last post by:
Whilst browsing Flipcode I noticed this code: class CConsole: public I_TextOutput { public: ... void Release() { delete this; } ... };
3
by: Songling | last post by:
Hi gurus, Just learnt from my co-worker that it's safe to delete a null pointer. I tried it on sun box (and linux), nothing bad happens. So it seems to be true. But does it apply to all...
2
by: bebelino | last post by:
Hello, this should be an easy one, but I've had always troubles with it. How to pass trough a querydef-variable, form-variable and so on from a function to the caller-routine? Is there a simply...
21
by: Marc DVer | last post by:
I am trying to create a query that can be loaded as a querydef object but not having to assign values to the parameters if I don't want to. Normally when using a parameter query in VBA my code...
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
4
by: George2 | last post by:
Hello everyone, Here is Bjarne's exception safe sample, http://www.research.att.com/~bs/3rd_safe.pdf template <class T> class Safe {
10
by: mirandacascade | last post by:
Question toward the bottom of this post....background information immediately below. Access 97 SQL Server 2000 Please note: although the subject line uses the word 'bloat', this post is NOT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.