By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,497 Members | 2,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,497 IT Pros & Developers. It's quick & easy.

4 steps or better in one step?

P: n/a
RLN

RE: Access 2003

I received an app to maintain.

The existing code simply flushes the contents of a table.
Here, they did it in 4 distinct steps (assuming the table exists, has
data, etc.)

' Open the Work1 Table
DoCmd.OpenTable "Work1", acViewNormal, acEdit

' Selects all records in the Work1 Table
DoCmd.RunCommand acCmdSelectAllRecords

' Deletes all records in the Work1 Table
DoCmd.RunCommand acCmdDeleteRecord

' Close the Work1 Table
DoCmd.Close acTable, "Work1"

I consolidated the above 4 lines to one line:
DoCmd.OpenQuery "qryFlushWork1Table", acViewNormal, acEdit

Aside from the obvious convenience of code maintenenance, is there any
real advantage in terms of speed and/or internal system efficiency to
use my one step as opposed to the existing four steps?

May 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"RLN" <rl***************@yahoo.com> wrote in
news:11**********************@j33g2000cwa.googlegr oups.com:

RE: Access 2003

I received an app to maintain.

The existing code simply flushes the contents of a table.
Here, they did it in 4 distinct steps (assuming the table
exists, has data, etc.)

' Open the Work1 Table
DoCmd.OpenTable "Work1", acViewNormal, acEdit

' Selects all records in the Work1 Table
DoCmd.RunCommand acCmdSelectAllRecords

' Deletes all records in the Work1 Table
DoCmd.RunCommand acCmdDeleteRecord

' Close the Work1 Table
DoCmd.Close acTable, "Work1"

I consolidated the above 4 lines to one line:
DoCmd.OpenQuery "qryFlushWork1Table", acViewNormal, acEdit

Aside from the obvious convenience of code maintenenance, is
there any real advantage in terms of speed and/or internal
system efficiency to use my one step as opposed to the
existing four steps?

First the query is faster. secondly, it doesn't open the table
to whoever is viewing. Thirdly, there's less chance of error,
because if someone has a second table open and clicks on hte
other table while the table is opening, you've deleted the data
from the wrong table.

you can make it simpler by just
DoCmd.runSQL "Delete * from Work1"


--
Bob Quintal

PA is y I've altered my email address.
May 24 '06 #2

P: n/a
RLN
Bob,
Thank you kindly for your input. I appreciate it.
Sorry for the late reply, as I hadn't had a chance to get back in for a
while.

Regards,
RLN

Jun 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.