473,396 Members | 1,738 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,396 software developers and data experts.

When to requery Form after running Update query?

I'm a little nervous about slamming my database with a dozen Update queries
in a loop that all modify RecordSources of open forms. Will the use of
DoEvents and/or a Sleep function ameliorate any risk involved in doing this?
Should I include a Requery in the loop after executing each query?

For example:

For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
Next

I have about a dozen queries that I want to run in a loop like this, all
updating (mainly deleting records from) the different tables that are part
of (i.e. included in the queries that are) the RecordSource for currently
open forms.

Should I do this:

For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
DoEvents
Forms("frmMain").Requery
Next

What about this:

Private Declare Sub Sleep _
Lib "kernel32" ( ByVal dwMilliseconds As Long )
For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
Forms!frm0.Requery
DoEvents
Sleep 500
Forms("frmMain").Requery
Next

Other options?

Thanks in Advance.
Nov 13 '05 #1
4 6896
The DoEvents in the loop is probably a good idea, but won't cause the form
to show the changes. If you run an Update Query, the DoEvents may let the
form's auto refresh run to show those changes, but deleted or added records
won't show until you requery. One exception to this may be that the refresh
of the form will cause a deleted record to show as #Deleted.

The Sleep function will cause Access to pause and release CPU time to other
applications that may be running, it won't help within Access.

Depending on how long it takes to run all of the queries, I would probably
just do one requery after exiting the loop.

If these queries are dependent on each other (i.e. you want them all for
complete or roll the whole thing back if one of them fails), you may want to
consider wrapping them in a transaction. This may also help with the form
since the changes won't actually be committed to disk until you commit the
transaction, essentially writing all of the changes at one time.

--
Wayne Morgan
Microsoft Access MVP
"deko" <www.clearpointsystems.com@use_contact_form.com> wrote in message
news:y8******************@newssvr13.news.prodigy.c om...
I'm a little nervous about slamming my database with a dozen Update
queries
in a loop that all modify RecordSources of open forms. Will the use of
DoEvents and/or a Sleep function ameliorate any risk involved in doing
this?
Should I include a Requery in the loop after executing each query?

For example:

For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
Next

I have about a dozen queries that I want to run in a loop like this, all
updating (mainly deleting records from) the different tables that are part
of (i.e. included in the queries that are) the RecordSource for currently
open forms.

Should I do this:

For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
DoEvents
Forms("frmMain").Requery
Next

What about this:

Private Declare Sub Sleep _
Lib "kernel32" ( ByVal dwMilliseconds As Long )
For each varQry in Array("qryDeleteOldTransactions", _
"qryDeleteClient Acct", etc., etc.)
db.Execute varQry
Forms!frm0.Requery
DoEvents
Sleep 500
Forms("frmMain").Requery
Next

Other options?

Thanks in Advance.

Nov 13 '05 #2
> The DoEvents in the loop is probably a good idea, but won't cause the form
to show the changes. If you run an Update Query, the DoEvents may let the
form's auto refresh run to show those changes, but deleted or added records won't show until you requery. One exception to this may be that the refresh of the form will cause a deleted record to show as #Deleted.

The Sleep function will cause Access to pause and release CPU time to other applications that may be running, it won't help within Access.

Depending on how long it takes to run all of the queries, I would probably
just do one requery after exiting the loop.
Sounds good. From what you've suggested, I'm considering this:

For Each varQry in Array([UpdateQry list])
db.Execute varQry
DoEvents
Sleep 100
Next
Forms("frmMain").Requery

The Updating in question does not need to be quick - just safe and
reliable - so I figured I'd put the DoEvents and Sleep in there. The only
reason I thought I needed to Requery the form after executing each Update
query is because I thought I might run into a "the data has changed" error
or some other record locking issue - since I am updating the RecordSource of
an open form multiple times. But if I only need to Requery once, that's
fine with me.
If these queries are dependent on each other (i.e. you want them all for
complete or roll the whole thing back if one of them fails), you may want to consider wrapping them in a transaction. This may also help with the form
since the changes won't actually be committed to disk until you commit the
transaction, essentially writing all of the changes at one time.


At this point, the queries are not dependent, but thanks for the heads up.

Nov 13 '05 #3
I would remove the Sleep, it will only slow things down. As stated, Sleep
will allow CPU cycles for other programs, it won't help within Access itself
and the DoEvents will do both.

--
Wayne Morgan
MS Access MVP
"deko" <www.clearpointsystems.com@use_contact_form.com> wrote in message
news:hC*****************@newssvr14.news.prodigy.co m...
The DoEvents in the loop is probably a good idea, but won't cause the
form
to show the changes. If you run an Update Query, the DoEvents may let the
form's auto refresh run to show those changes, but deleted or added

records
won't show until you requery. One exception to this may be that the

refresh
of the form will cause a deleted record to show as #Deleted.

The Sleep function will cause Access to pause and release CPU time to

other
applications that may be running, it won't help within Access.

Depending on how long it takes to run all of the queries, I would
probably
just do one requery after exiting the loop.


Sounds good. From what you've suggested, I'm considering this:

For Each varQry in Array([UpdateQry list])
db.Execute varQry
DoEvents
Sleep 100
Next
Forms("frmMain").Requery

Nov 13 '05 #4
> I would remove the Sleep, it will only slow things down. As stated, Sleep
will allow CPU cycles for other programs, it won't help within Access itself and the DoEvents will do both.


10-4. There's no sense in slowing things down for no reason.

Thanks for the help!
Nov 13 '05 #5

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

Similar topics

5
by: Scott | last post by:
I have created a form that has a few combo boxes on it. On the form I have ComboBoxA which selects data from a region, and ComboBoxB that selects individual locations within a selected region. I...
1
by: kimj.dk | last post by:
Hi, I have a form with a subform where the subform uses the value from a combo box on the main form as a query criteria. I don't want the subform to update or get data before the user has selected...
2
by: jpatchak | last post by:
I am experiencing two distinct problems with the Requery method in Access 2003. Problem 1: I have a series of text boxes on my form. The control sources of these text boxes are used in...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
8
by: Michael R | last post by:
Dear users and experts, An unbound combo box in my form is responsible for changing a city name for an update query that creates a temprorary table which the form uses as its record source. In...
2
by: sandpking | last post by:
I have the query below (as a row source)update a list box with all the employees of a supervisor. The problem is it doesn't automatically update when a the referened field on the form (supervisor)...
2
by: DeanL | last post by:
Hi everyone, I have a subform in datasheet view that is used to display the contents of a single table. I have another subform with a query feeding it to give a count of how many particular...
10
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I...
6
by: deewe | last post by:
Hello, On an LostFocus event I'm trying to update another field that is tied to a DLookUp query. I'm able to update all the form fields but I don't find a way to update only one field. The...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...

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.