Run query on close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

In the "On Close" event, I have a query that I'd like to run. Currently,
it's set as an "Open Query" macro, which works, but I'd like it just to run
automatically. Others use the form, and I don't want them to get confused
when the query box pops up. I don't see a "Run Query" macro -- is it
possible to do this?

Thanks,

Patti
 
Patty,
I assume that the "On Close Event" is that of a form. If so, you can launch
the query by placing the following line in the On Close event of your form:

DoCmd.OpenQuery "your query name here".

If the potentially confusing "query box" is asking for a parameter, you can
also pass the necessary values to the query without user interaction.

If you need help passing a value to your query, post your sql code here.

HTH
Jason
 
Hi Jason,

Thanks for replying! The code has the same effect as my macro -- it just
opens the query -- I still get the box with the message "You are about to run
an update query..." that requires the user to select "Yes". I want to bypass
that box and just automatically run the query. Is this possible?
 
Yes. All you have to do is turn the warnings off before your query runs.
Turning them back on afterthe query is up to you, but you may want to to
ensure that you get the system warnings when you might need them.

To turn the warnings off just add this line above the statement you are
using to run the query:

DoCmd.SetWarnings False

To turn the warnings on you would only need to include this line below your
query line:

DoCmd.SetWarnings True

As a side note, you could also use 0 (the number zero) for false and -1 for
true.

Jason
 
Back
Top