docmd.setwarnings = false
docmd.runquery "Qerey1"
docmd.setwarnings = true
put it in the event you want it to run from.
Mike
Main Topics
Browse All TopicsHi,
I have a form and several subforms. I would like to setup an event that would allow an update query (already written and works) to run. I do not want to see the results of the query, I just need the results updated to be used in another form.
Example:
Form 1 queries and returns times.
Update query updates time table with times.
Form 2 pulls data from time table and displays.
Works great with the button but I would like to have it so that a button doesn't need to be pushed. I saw on the web where some guy took the code from the button and replaced it to point to his form and then put it in an event. I did the same but wasn't sure what to change to have it point to the form.
Any help would be appreciated.
Heather
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
re:> Form 1 queries and returns times.
By 'returns' do you mean it updates a text box? If so, OnChange event of the text box is where you will be putting your code so your "Update query updates time table with times" and "Form 2 pulls data from time table and displays".
If not, the other option is using timer even of the form with timer set at 2000 (2 second). An in order for the code is fire only when it is needed, you need to add:
Public bolDontRun As Boolean
in the timer:
If bolDontRun = False Then
bolDontRun = True
CurrentDB.Execute "Update...."
End If
And somewhere in your form 1, you need to set bolDontRun = False to signal timer to fire the code again.
Mike
The form and a subform is open. Once the user types in the last time (time out), the subform requeries and applies the new values. At that time, on it's refresh, I would like the update query to run. This query will update a table that another form will be pulling values from.
So, I guess I would like the update query to run when the user clicks on the subform and after the subform is updated.
I hope this helps....I give the above suggestions a try.
Happy New Year to everyone. I appreciate the help!
Heather
Going over parts of your last post:
re:> Once the user types in the last time (time out), the subform requeries and applies the new values.
The key part her is "subform requeries". The event I suspect you need to try is the On Current event of the subform. And, if the user enters the date to the subform:
CurrentDB.Execute "Update...." 'in On Current event of the subform
It will be nice for you post the SQL of your query to see if it needs update using a value from the form or the subform.
Happy New Year to you as well.
Mike
Here is the sql scripts...by the way, I tried the above code in various event locations and nothing worked. Not sure if I was using the correct info. For the following:
docmd.setwarnings = false
docmd.runquery "Qerey1" (I used the name of the query "Update TimeUsed Query"
docmd.setwarnings = true
Maybe I should have used the control name...not sure if the query would have one.
Here are the queries:
Time Used: Main Form
SELECT ParentInfo_TB.ParentID, TimeUsed_TB.ParentID, ParentInfo_TB.ParentID, ParentInfo_TB.Parent_LastN
FROM ParentInfo_TB INNER JOIN TimeUsed_TB ON ParentInfo_TB.ParentID = TimeUsed_TB.ParentID
ORDER BY TimeUsed_TB.ParentID;
Time Query: Subform
SELECT [Time Query].TimeUsed_TB.ParentI
FROM [Time Query] INNER JOIN Payment_tbl ON [Time Query].ParentInfo_TB.Paren
Update Query (Background Query):
UPDATE (ParentInfo_TB INNER JOIN [Used Time Query] ON ParentInfo_TB.ParentID = [Used Time Query].ParentID) INNER JOIN Payment_tbl ON ParentInfo_TB.ParentID = Payment_tbl.ParentID SET Payment_tbl.TotalHours_Lef
Thanks again,
Heather
In the events you try, have
MsgBox "subform events fired" 'using the event name as it applies
This is to make sure, in requerying of the subform's on current event it fires. If it doesn't fire (which it should in requeryin it) we have to see what the problem is.
After we located the event, use
'docmd.setwarnings = false
docmd.runquery "Qerey1" (I used the name of the query "Update TimeUsed Query"
'docmd.setwarnings = true
to see if there is some kind of error with the running of the query. We can remove the single qoutes later.
Mike
Hi Mike,
I got the message box to pop up and fire the query. I had to replace the runquery with the "Update query statement." That worked!! BUT, I it is firing the update query when the form is open. I tried to move the update query around to something other than CURRENT like on click, or after update, etc; but it doesn't seem to be firing the update query when clicked.
Any suggestions as to where I can put the query and why it is on only working with the on Current event?
Thanks,
Heather
Hi Heather,
I guess we are getting closer to solve it. You probably remeber my post asking you, in a module, to include:
Public bolDontRun As Boolean
The value of this will set to true when the user enter a value that running the update query becomes necessary. Say, when user enters a time value in a text box, then in that text box after update enter:
bolDontRun = True
Now, chnage your code in the on current event to:
If bolDontRun = True Then
CurrentDB.Execute "Update...."
bolDontRun = False
End IF
This way, it updates only once. When a value is entered into a specific text box.
Mike
Business Accounts
Answer for Membership
by: flavoPosted on 2007-12-30 at 14:24:23ID: 20552314
When would you like the query to run? when the form opens, when the user does something else?
Dave