469,917 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

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 2897
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Paul Drummond | last post: by
3 posts views Thread by Bruno van Dooren | last post: by
3 posts views Thread by Sebastian C. | last post: by
6 posts views Thread by Edd Dawson | last post: by
2 posts views Thread by Adam Honek | last post: by
8 posts views Thread by Dox33 | last post: by
20 posts views Thread by Pilcrow | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.