Questions about timing of calls & returns

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

Guest

Hi to All

I understand that when a form is opened from within a sub, the proc will
continue to execute after the DoCmd.Open unless the form is modal.

What happens when an action query (e.g. make table) is invoked within a sub?
Does the query complete before the sub resumes execution? Also, what about
when one sub calls another - does the calling sub wait for the called routine
to return?

Thanks!
 
Action queries are asynchronous, meaning the code will not wait for it to
finish.
Calls to sub routines are synchronous. The code will wait for the sub
routine to finish.

Barry
 
Thanks Barry.

Any suggestions as to how to insure that the query has
completed other than using the timer event and taking a guess at how long to
wait?
 
mac@hoc said:
I understand that when a form is opened from within a sub, the proc will
continue to execute after the DoCmd.Open unless the form is modal.

What happens when an action query (e.g. make table) is invoked within a sub?
Does the query complete before the sub resumes execution? Also, what about
when one sub calls another - does the calling sub wait for the called routine
to return?


Access uses many different execution tasks at various
priority levels so it's no surprise that VBA code is
asynchronous from all the other things.

You can run an action query (not a SELECT query)
synchronously by using the Execute method. E.g.

DbEngine(0)(0).Execute "SELECT . . . INTO . . ."

Check it out in VBA Help for details about its options.
You probably want to use the dbFailOnError argument. If you
want to know how many records were put in the new table you
can use:
MsgBox DbEngine(0)(0).RecordsAffected
 
Thanks to Barry & Marshall! I had been pondering this question a long time
and it's nice to have some answers.
 
Back
Top