473,320 Members | 2,029 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,320 software developers and data experts.

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 3087
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
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...
3
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. ...
3
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...
6
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...
31
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
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...
4
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...
8
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....
20
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 -----------------------------------...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.