473,409 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Is Access consistent with the order of events when opening a form from within a procedure?

MLH
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?
Nov 12 '05 #1
9 3082
MLH
Excuse me for leaving off the specific MyForm2
events I was concerned with, they are...
OPEN
LOAD
RESIZE
ACTIVATE
CURRENT

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mon, 22 Dec 2003 10:49:53 -0500, MLH <CR**@NorthState.net> wrote:
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?


Nov 12 '05 #2
On Mon, 22 Dec 2003 10:49:53 -0500, MLH <CR**@NorthState.net> wrote:

The use of DoEvents would throw things off.
Also setting Cancel to True in Form_Open.
Perhaps also resizing your form in Form_Open or Form_Load.

-Tom.

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?


Nov 12 '05 #3
WFICT, no, there is no case where those events would not all fire prior to the
MsgBox call. However, writing code that depends on sequence is generally good
to avoid if you can think of an easy way to avoid it, because such code tends
to be more modular and cleaner anyway, and because it's bossible that new
versions of the software or new code of yours in the form itself could cause
breakage of the logic.

Example. Occasionally, you find something in Access that you need to do when
a form opens that does not work right when attempted from either the Open or
Load events, so you set up a 1ms timer, and call it from there. Now, even
though Access would perform as expected, you have still broken the calling
code by moving the logic.

Of course, using the timer event, then, is another thing you want to try to
avoid for musch the same reason, but the point is that if you can avoid
strenuous expectations by any part of the code, you have more slack elsewhere
if you need it.

On Mon, 22 Dec 2003 10:57:07 -0500, MLH <CR**@NorthState.net> wrote:
Excuse me for leaving off the specific MyForm2
events I was concerned with, they are...
OPEN
LOAD
RESIZE
ACTIVATE
CURRENT

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mon, 22 Dec 2003 10:49:53 -0500, MLH <CR**@NorthState.net> wrote:
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?


Nov 12 '05 #4
CR**@NorthState.net (MLH) wrote in
<4m********************************@4ax.com>:
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?


Successive lines of code executed asynchronously, so, the
MessageBox could fire before all the events of the form opening
would fire.

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.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #5
MLH
Interesting!
xxxxxxxxxxxxxxxxxx
On Mon, 22 Dec 2003 09:12:22 -0700, Tom van Stiphout
<to*****@no.spam.cox.net> wrote:
On Mon, 22 Dec 2003 10:49:53 -0500, MLH <CR**@NorthState.net> wrote:

The use of DoEvents would throw things off.
Also setting Cancel to True in Form_Open.
Perhaps also resizing your form in Form_Open or Form_Load.

-Tom.

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?


Nov 12 '05 #6
On Mon, 22 Dec 2003 18:19:26 GMT, dX********@bway.net.invalid (David W.
Fenton) wrote:
CR**@NorthState.net (MLH) wrote in
<4m********************************@4ax.com>:
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?
Successive lines of code executed asynchronously, so, the
MessageBox could fire before all the events of the form opening
would fire.


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.
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.


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.
Nov 12 '05 #7
TC
The others have said no, in the absence of a doevents, the open/load etc.
events will fire before you get to the messagebox. But IMO, this is not
because ms designed it that way. It is a (probably not deliberate)
side-effect of the fact that VBA is single-threaded. The thread in question
is busy opening the called form; there is just no other thread available for
the msgbox. But if the called form does a doevents, that thread stops, & all
sorts of curious race conditions can happen then.

HTH,
TC
"MLH" <CR**@NorthState.net> wrote in message
news:4m********************************@4ax.com...
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?

Nov 12 '05 #8
MLH
Now that's what I'm talkin' about. I never put my finger
on it but, deja vu, I seem to remember encountering
strange effects I could never put my finger on. I couldn't
replicate them (weary from the work-around battle) and
I ended up forgetting about the situation. I'm going to
do some testing around your comments... Thx.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx
On Tue, 23 Dec 2003 14:49:37 +1200, "TC" <a@b.c.d> wrote:
The others have said no, in the absence of a doevents, the open/load etc.
events will fire before you get to the messagebox. But IMO, this is not
because ms designed it that way. It is a (probably not deliberate)
side-effect of the fact that VBA is single-threaded. The thread in question
is busy opening the called form; there is just no other thread available for
the msgbox. But if the called form does a doevents, that thread stops, & all
sorts of curious race conditions can happen then.

HTH,
TC
"MLH" <CR**@NorthState.net> wrote in message
news:4m********************************@4ax.com.. .
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?


Nov 12 '05 #9
On Tue, 23 Dec 2003 21:34:45 -0500, MLH <CR**@NorthState.net> wrote:

Doevents should be used very sparingly, and judiciously.

I once was called to a job where the app was doing "weird
unreproducible things". Within an hour it worked again, after I did a
global find & replace for DoEvents with 'DoEvents (commenting out
several dozen occurrences).
I spent a bit more time inspecting each one, and eventually
uncommented one or two.

-Tom.

Now that's what I'm talkin' about. I never put my finger
on it but, deja vu, I seem to remember encountering
strange effects I could never put my finger on. I couldn't
replicate them (weary from the work-around battle) and
I ended up forgetting about the situation. I'm going to
do some testing around your comments... Thx.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
On Tue, 23 Dec 2003 14:49:37 +1200, "TC" <a@b.c.d> wrote:
The others have said no, in the absence of a doevents, the open/load etc.
events will fire before you get to the messagebox. But IMO, this is not
because ms designed it that way. It is a (probably not deliberate)
side-effect of the fact that VBA is single-threaded. The thread in question
is busy opening the called form; there is just no other thread available for
the msgbox. But if the called form does a doevents, that thread stops, & all
sorts of curious race conditions can happen then.

HTH,
TC
"MLH" <CR**@NorthState.net> wrote in message
news:4m********************************@4ax.com. ..
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?


Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
0
by: jphelan | last post by:
I have a subform that works fine until you import it into a new database when it crashes if you try to open it in either disign or form view. The form, "Attendees_Subform" in my application was...
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
1
by: KRSharp | last post by:
I am new to Access, so bear with me. I think this is possible, but I am not sure how to get this going. I am trying to develop a database that will allow me to create a manufacturing schedule...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.