473,890 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange behaviour of Form_Activate

Ian
Hi everyone,

I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.

After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:

Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End

This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.

Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.

Any help / advice on this issue would be gratefully received!

Thanks,

Ian

Sep 5 '06 #1
5 3114
Hi Ian,

You have to understand that to close the form it must become the active
form, albeit for just a blink of an eye. So when your routine tries to
close the form it immediatley becomes active, and the Form_Activate
routine starts running. Before that finishes you try and close the
form, you can't and the routine stops, then the Form_Activate finishes.

Hope that this helps,

Nick

Ian wrote:
Hi everyone,

I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.

After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:

Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End

This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.

Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.

Any help / advice on this issue would be gratefully received!

Thanks,

Ian
Sep 5 '06 #2
Ian
That explanation makes sense to me, but I then don't see why my Form
Close event would then fire a second time?

Nick 'The database Guy' wrote:
Hi Ian,

You have to understand that to close the form it must become the active
form, albeit for just a blink of an eye. So when your routine tries to
close the form it immediatley becomes active, and the Form_Activate
routine starts running. Before that finishes you try and close the
form, you can't and the routine stops, then the Form_Activate finishes.

Hope that this helps,

Nick

Ian wrote:
Hi everyone,

I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.

After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:

Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End

This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.

Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.

Any help / advice on this issue would be gratefully received!

Thanks,

Ian
Sep 5 '06 #3
I'm open to correction if anyone else knows better than me, but I would
have said that the event fires a second time because it is getting the
focus back from the code that was trying to close the form.

Nick

Ian wrote:
That explanation makes sense to me, but I then don't see why my Form
Close event would then fire a second time?

Nick 'The database Guy' wrote:
Hi Ian,

You have to understand that to close the form it must become the active
form, albeit for just a blink of an eye. So when your routine tries to
close the form it immediatley becomes active, and the Form_Activate
routine starts running. Before that finishes you try and close the
form, you can't and the routine stops, then the Form_Activate finishes.

Hope that this helps,

Nick

Ian wrote:
Hi everyone,
>
I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.
>
After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:
>
Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End
>
This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.
>
Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.
>
Any help / advice on this issue would be gratefully received!
>
Thanks,
>
Ian
Sep 5 '06 #4
Ian
Hi Nick,

Thanks for keeping going with this one for me!

I also thought that it might be restarting from where it left off after
the activate call ran, but the text output to my immediate window
suggests that the close event is not restarting but running a second
time?

Thanks again,

Ian

Nick 'The database Guy' wrote:
I'm open to correction if anyone else knows better than me, but I would
have said that the event fires a second time because it is getting the
focus back from the code that was trying to close the form.

Nick

Ian wrote:
That explanation makes sense to me, but I then don't see why my Form
Close event would then fire a second time?

Nick 'The database Guy' wrote:
Hi Ian,
>
You have to understand that to close the form it must become the active
form, albeit for just a blink of an eye. So when your routine tries to
close the form it immediatley becomes active, and the Form_Activate
routine starts running. Before that finishes you try and close the
form, you can't and the routine stops, then the Form_Activate finishes.
>
Hope that this helps,
>
Nick
>
Ian wrote:
Hi everyone,

I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.

After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:

Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End

This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.

Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.

Any help / advice on this issue would be gratefully received!

Thanks,

Ian
Sep 5 '06 #5
Like I said the code starts closing the form, then the form gets the
focus, the OnActivate starts running, the form cannot be closed because
the OnActivate is running, the form loses the focus as the code that
was trying to close it finishes, then the form receives teh focus again
and the OnActivate run again.

If I were you I would put my code behind some other event than
OnActivate.

Good luck

Nick
Ian wrote:
Hi Nick,

Thanks for keeping going with this one for me!

I also thought that it might be restarting from where it left off after
the activate call ran, but the text output to my immediate window
suggests that the close event is not restarting but running a second
time?

Thanks again,

Ian

Nick 'The database Guy' wrote:
I'm open to correction if anyone else knows better than me, but I would
have said that the event fires a second time because it is getting the
focus back from the code that was trying to close the form.

Nick

Ian wrote:
That explanation makes sense to me, but I then don't see why my Form
Close event would then fire a second time?
>
Nick 'The database Guy' wrote:
>
Hi Ian,

You have to understand that to close the form it must become the active
form, albeit for just a blink of an eye. So when your routine tries to
close the form it immediatley becomes active, and the Form_Activate
routine starts running. Before that finishes you try and close the
form, you can't and the routine stops, then the Form_Activate finishes.

Hope that this helps,

Nick

Ian wrote:
Hi everyone,
>
I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This action cannot be
carried out whilst processing a form or report event). This was tracked
down to erroring when trying to carry out the DoCmd.Close acForm call.
>
After some investigation, I have tracked the problem down to some
strange interactions between the forms Activate event and the click
event on the button in question. I have used a combination of some code
to stop the error from occuring and the the immediate window to test
the code flow, and have discovered the following:
>
Activate Start
Form Close Start
Form Close Handled End
Activate End
Form Close Start
Form Close End
>
This is the output from the immediate window after placing a text
output at the start, end of the Activate event and the start, end of
the button event code. The 'Form Close Handled End' occurs when my code
to stop error 2585 is used. It appears to suggest that the Activate
event fires, then the Form Close subroutine starts immediately after.
This then is handled and quit without closing the form by my new code.
The Activate event then gets round to finishing and the form close
event runs a second time.
>
Although I have now created some code to work around this issue, I am
intrigued as to whether this is a bug that I have stumbled across or I
just don't quite understand the way the two event interact. It seems a
very strange problem.
>
Any help / advice on this issue would be gratefully received!
>
Thanks,
>
Ian
Sep 7 '06 #6

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

Similar topics

2
1980
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
3
2367
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
3
4881
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP Developer (SP3 for Office, SP1 for developer, JET40SP8) on Windows XP Home Edition (SP1). The same behaviour occurs on Windows 98 too.
6
2940
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command line arguments to the program, the behaviour of one of the functions changes mysteriously. I have...
31
2661
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
2
3542
by: Adam Honek | last post by:
In VB6 and earlier we had a form_activate() event whereby it always fired every time the form gained was focussed. In VB.net I don't see it and we have a _activate() event. What event would I use for the background form to refresh once the foreground form has been closed?
4
2105
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages this way like: public class UiMsg { public enum MsgType { StatusOk }; public MsgType Type;
8
5330
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
20
2255
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code ----------------------------------- #include <stdio.h> int main (void) { char xx="abcd"; char * p1 = xx;
0
9972
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9812
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10795
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10444
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9612
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7154
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6032
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4653
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.