deactivate event fires every OTHER time

  • Thread starter Thread starter Maxine G
  • Start date Start date
M

Maxine G

I have two forms, a menu and a data entry form. The entry form is bound
to a query against linked SQL server tables. In the deactivate event, I
have some code which asks the user if they want to save their changes and
they can respond with yes, no or cancel. If they press cancel, the entry
form stays active with the changes still entered.

So, if I'm on the entry form and have entered data, and then click on the
menu, the deactivate event fires and I get the correct prompt. If I press
cancel, I stay on the entry form. But if I click AGAIN on the menu form,
I've confirmed that the deactivate event doesn't fire so the menu form
becomes active without prompting the user. If I then click back to the
entry form and do it all over, the deactivate event DOES run and the
prompt is issued. So, the deactivate event is firing every OTHER time I
click on the menu form.

I notice that on the times that the deactivate event DOES fire, and I
select cancel and return to the entry screen, the activate event for the
entry screen fires, and then the activate event for the menu screen fires
after that even though the entry screen is the one which will have focus.
I suspect this is related.

Thanks in advance for any help on this question.

-Maxine
 
Deactivate() is not a common event from which to ask the user to save
changes.

Perhaps use the form's BeforeUpdate event? That will fire when the form is
actually about to save a new or edited record. If you cancel that event, the
new or updated data is not saved, but remains in the form. If you Me.Undo,
the new or updated data is discarded & the form goes back to "square one".

HTH,
TC
 
Thanks. I've used deactivate in other settings for this (such as VB). I
don't think the BeforeUpdate event will fire if you simply click off the
form. And that's what we're trying to do - prevent the user from leaving
the form without explicitly saving or canceling changes.

-Maxine
mg at pcg dot net
 
You are right that BeforeUpdate will not fire if you simply click off the
form.

Could you make the form Modal? Then, he can not click off the form *at all*.
Once he is in it, he must close it before he can click on to anything else.
And at that point, if there is an unsaved record, BeforeUpdate will fire
then.

Can you say a bit more about why you do not want them to click off the form
with unsaved changes?

HTH,
TC
 
Modal's a possibility, except that the form will be used for viewing
existing data as well, and I don't want the user to have to close the
form when just viewing a form. Can you change the disposition of a form
on the fly, for instance make it modal after they've entered data?

To me it just makes sense that the user should have to complete changes
on one form before leaving the form, either by closing it or clicking on
another form. If the user starts entering data on another, related form
and assumes that the changes from the first form were saved, then there
could be integrity issues.

But if it can't be done, it's not the end of the world. It just seems
like I should be able to count on the deactivate event firing EVERY time
I click off a form.

Thanks,
Maxine
 
Modal's a possibility, except that the form will be used for viewing
existing data as well, and I don't want the user to have to close the
form when just viewing a form.

Yes, that makes sense.
Can you change the disposition of a form
on the fly, for instance make it modal after they've entered data?

I don't believe so.

To me it just makes sense that the user should have to complete changes
on one form before leaving the form, either by closing it or clicking on
another form. If the user starts entering data on another, related form
and assumes that the changes from the first form were saved, then there
could be integrity issues.

I hear what you say. But to avoid that, I think most access developers would
go the modal form way.

But if it can't be done, it's not the end of the world. It just seems
like I should be able to count on the deactivate event firing EVERY time
I click off a form.

I've tried using deactivate for other things & never quite understood when
it fired & did not fire. I eventually gave up on it.

Cheers,
TC
 
Back
Top