On Mon, 22 Dec 2003 18:19:26 GMT,
dXXXfenton@bway.net.invalid (David W.
Fenton) wrote:
[color=blue]
>CRCI@NorthState.net (MLH) wrote in
><4m3euvk9ebh09dqjnbv2pt7k1u9hgreo9v@4ax.com>:
>[color=green]
>>If you have these lines in code on MyForm1...
>>
>>DoCmd OpenForm "MyForm2`"
>>MsgBox "I opened MyForm2"
>>
>>Is it #ALWAYS# true that all form events
>>on MyForm2 will occur before the MsgBox
>>statement in MyForm1 is processed?
>>
>>Is there ever an exception that might create
>>a race condition in which the MsgBox line
>>would be processed before one or more of
>>the MyForm2 events?[/color]
>
>Successive lines of code executed asynchronously, so, the
>MessageBox could fire before all the events of the form opening
>would fire.[/color]
Access does many things aynchronously, but I have yet to notice a case when
the next statement after an OpenForm could fire before all of the initial form
open events (not that I advocate relying on this).
One certainly must be careful with things like expecting a table or report
export to be completed before trying to do something with the resulting file.
In this case, adding a singe DoEvents call will force VBA to wait until the
export completes.
[color=blue]
>A kludgy way to force it would be:
>
> DoCmd OpenForm "MyForm2", , , , , acDialog
> [in the form's Activate event, set Me.Visible = False]
> MsgBox "I opened MyForm2"
> Forms!MyForm2.Visible = True
>
>Of course, at that point, it's still a dialog form.
>
>And I can't guarantee that this will always work.
>
>If you really want code to execute only after a form has finished
>opening, the code needs to be in the last relevant event of the
>form. And, even then, you can't control it for sure, as other
>things can intervene.[/color]
I generally have good luck using the On Current event handler for these cases,
and making sure one of the controls' value property can be accessed without
error. On Current is usually called once or twice before the recordset is
loaded, but once the Value properties are accessible, everything is ready to
roll.