What does Access do in the code like this ?

  • Thread starter Thread starter Albert
  • Start date Start date
A

Albert

Hello All Expert,

if [form A] opens [form B] and [form B] has a text box [T] and I code like
this :

DoCmd.OpenForm "Form B"
Forms("B")![T] = "Hello"

Does Access automatically know to pause code in second line until Form B is
opened and ready to accept any referenced ?

Or do we have to write some code after first line to check whether Form B is
completely opened ?

I ask this becasue AFAIK Access is multi thread. Form B should be opened and
run any code bind to it. At the same time form A run second line of code
without any synchronize with form B. But every time I run the above code, It
work well. What is actually happen ?

TIA,
Albert
 
Albert said:
if [form A] opens [form B] and [form B] has a text box [T] and I code like
this :

DoCmd.OpenForm "Form B"
Forms("B")![T] = "Hello"

Does Access automatically know to pause code in second line until Form B is
opened and ready to accept any referenced ?

Or do we have to write some code after first line to check whether Form B is
completely opened ?

I ask this becasue AFAIK Access is multi thread. Form B should be opened and
run any code bind to it. At the same time form A run second line of code
without any synchronize with form B. But every time I run the above code, It
work well. What is actually happen ?


What actually happens is hidden in the internals of Access.
OTOH, It seems clear that formB's Open event should have
completed, but I don't think you can rely on the Load event
having been started, so I would not use code like your's.

You can bypass this whole issue by using OpenArgs to pass
the value to FormB so it can set the value when it's ready:

DoCmd.OpenForm "Form B", OpenArgs:="Hello"

then in formB:

Sub Form_Load(
Me!T = Me.OpenArgs
 
Back
Top