473,385 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,385 software developers and data experts.

Append vs Recordset

I have a loop that loops through all records in all tables that have
"TSE" as the first letters. In that loop, based upon conditions of the
current record I have to add records to 1 of 5 different table. Now is
it quicker to use 5 recordsets and add a new record to them, or is it
faster to use append statements to append the records.

ex.

for each t in db.tabledefs
if t.name like "tse*" then
set rs = db.openrecordset(t.name)
do while not rs.eof
if condition1 then
rsA.addnew
rsA.update
' strsql = append statment for A here
' docmd.runsql strsql
elseif condition2 then
rsB.addnew
rsB.update
' strsql = append statment here
' docmd.runsql strsql
end if
loop
end if
next t

which is better?

Dec 22 '06 #1
1 4763
Jason Lepack wrote:
I have a loop that loops through all records in all tables that have
"TSE" as the first letters. In that loop, based upon conditions of the
current record I have to add records to 1 of 5 different table. Now is
it quicker to use 5 recordsets and add a new record to them, or is it
faster to use append statements to append the records.

ex.

for each t in db.tabledefs
if t.name like "tse*" then
set rs = db.openrecordset(t.name)
do while not rs.eof
if condition1 then
rsA.addnew
rsA.update
' strsql = append statment for A here
' docmd.runsql strsql
elseif condition2 then
rsB.addnew
rsB.update
' strsql = append statment here
' docmd.runsql strsql
end if
loop
end if
next t

which is better?
SQL is better 99.44% of the time. It may not be if recursive or
extensive record manipulation is being done, as in a time table
calculation where we assign periods, check the suitability of the
assignment, then make formative changes in several passes.

CurrentDb.Execute "UPDATE ATable Set AField =" & aValue, dbFailOnError
or
CurrentDb.Execute "UPDATE ATable Set AField ='" & aString & "'",
dbFailOnError

from help:
"The Execute method runs an action query. The dbFailOnError option can
allow your application to determine whether a QueryDef object fails to
perform its designated action for all records that meet its criteria.
As long as a QueryDef object is syntactically correct, it does not
generate an error-even if it fails to perform its action. The
dbFailOnError option rolls back any changes if the QueryDef object
cannot perform all the changes. This option also generates a run-time
error to help you perform any associated processing, such as providing
feedback to a user."

At one time I thought I should try to keep my action queries to a
minimum. I have no idea why. Perhaps because I saw so much Recordset
updating here and in MS examples. I was wrong.
Execute can be called millions of times; it stays fast, simple and
safe.

Recordsets almost always send more data over wires or loads more data
into memory than is required. Recordset updating often is problematic.
Recordset updating is slow. And pointers to Recordsets may have to be
explicitly released to prevent ghosting (nah, not anymore but it's an
old shibboleth that we're fond of.)

Dec 22 '06 #2

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

Similar topics

23
by: Rob Meade | last post by:
Lo all, Ok - this is what I was aiming to do, and then I thought - naahhh, that cant be right! query database results to recordset results to array using GetRows update values in one column...
5
by: Rob Meade | last post by:
evenin' k - I've got a recordset that I'm dumping another recordset into - because the source comes from a database that I cant update (probably makes more sense to me that bit) - anyway, I need...
7
by: Rob Meade | last post by:
Lo all, I'm having a little bit of trouble (betty...). I have removed some of the obvious stuff from this example (like connections being opened/closed etc) I create a recordset in ASP (not...
4
by: Agoston Bejo | last post by:
I would like to use an ADODB.RecordSet object to temporarily store some data and then iterate through it. Actually it needs to be a RecordSet only because it is a perfect choice as data structure...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
1
by: sanika1507 | last post by:
Hi .Actually I want to count the number of records in a recordset. So I m using the ADODB.Recordset. I just want some one to correct me. Set Cmd = Server.CreateObject("ADODB.Recordset") ...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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...

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.