Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop All Events Via A Button...

Status
Not open for further replies.

roystreet

Programmer
Oct 12, 2000
146
0
0
US
Hello,
I wanted to have a button that would allow me to stop all events on a form and close it. Currently, if a user decides to abort a form, the form will give them a popup that states they didn't enter in a name or number - Which ever field they didn't enter in a value. If they decide to close instead of completing the form - I would like them to be able to press a button that would stop all events from occurring so that they don't get a bunch of popups. I only want the validation popups to work if they go on to another new record, but they did not comply with the validation codes. I hope this question makes sense...

Thanks,
---roystreet
 
Hi Roy,

Look at these possibilities.

Is the form bound to a table? That may be where the edits are coming from. You may have to unbind the form.

Is the OnClose event for the form doing the editing? Bypass the edits if the "abort" button is clicked.

The OnClick for the "abort" button nulls all the fields on the screen. This might even work in lieu of unbinding the form.

Hope this helps.
 
Hello Girn13,
I have code that validates two fields in the form; unique_number and name. If both of these fields comply, the form will be saved in the table. (It is bound to a table) But if they decide, hey I don't have time to finish entering this information in - I'll do it later...But they leave the form partially complete and then they close the form - They begin have msgbox's popping up stating that they didn't enter in the number correctly or name correctly. These errors I want in the form. But if they want to close it early and do not save, I would like to avoid two msbox's from popping up before they can close the form. This is what I'm looking for. The code validates the two fields at Before Update.

Thanks,
---roystreet

I didn't exactly understand your response, but maybe I didn't explain my question well enough.
 
roystreet said:
[blue]But if they want to [purple]close it early and do not save[/purple], I would like to [purple]avoid two msbox's[/purple] from popping up before they can close the form. This is what I'm looking for. The code [purple]validates[/purple] the two fields at [purple]Before Update[/purple].[/blue]
The problem is, as soon as a textbox looses focus, via clicking just about anywhere else, the [purple]BeforeUpdate & AfterUpdate[/purple] events are triggered. [blue]So they always occur if code is resident in the events.[/blue]

Obviously you can't validate with the above events if your to achieve your goal. What you could have is two buttons [purple]Submit & Close Form[/purple]. Validation & saving would be done with Submit Button. Closing, easily done with the Form Close button

An alternate method would be to add a [purple]Close Form Option[/purple] to the messages, and you could handle it from there. Since there are a number of ways to close a form (who said thry have to click on a button!), this may be your best option.

Calvin.gif
See Ya! . . . . . .
 
roystreet said:
[blue]But if they want to [purple]close it early and do not save[/purple], I would like to [purple]avoid two msbox's[/purple] from popping up before they can close the form. This is what I'm looking for. The code [purple]validates[/purple] the two fields at [purple]Before Update[/purple].[/blue]
The problem is, as soon as a textbox looses focus, via clicking just about anywhere else, the [purple]BeforeUpdate & AfterUpdate[/purple] events are triggered. [blue]So they always occur if code is resident in the events.[/blue]

Obviously you can't validate with the above events if your to achieve your goal. What you could have is two buttons [purple]Submit & Close Form[/purple]. Validation & saving would be done with Submit Button. Closing, easily done with the Form Close button

An alternate method would be to add a [purple]Close Form Option[/purple] to the messages, and you could handle it from there. Since there are a number of ways to close a form (who said they have to click on a button!), this may be your best option.

Calvin.gif
See Ya! . . . . . .
 
Howdy! - The Before Update I'm referring to at this point is at the form level, not the field. I don't know if you knew that or not. That's why I thought it would be possible to cancel any events from even starting via button. I didn't think that the Before Update (at the form level, not the field) would run until you would do some action like moving between records or closing the form.

Thanks,
---roystreet
 
[blue]The Before Update I'm referring to at this point is at the form level, not the field.[/blue]
Yes . . . . I'm aware.

If you consider the[blue]Before Update[/blue] for the [purple]Form Event[/purple] occurs right after the [purple]Control Event[/purple] (no way to stop it!), the results are the same. . . . . How do you break in and close instead? How do you signify to this type of event that takes over, you want to do this! Considering it takes over simply by loosing focus . . . .

I think you see my point. The reason for my suggestion of the two buttons. . . . . So ya think?

Calvin.gif
See Ya! . . . . . .
 
Yup - the before update of the form will run every time an attempt to save is performed, whether it is a forced save of some kind, moving between records or closing the form when there are unsaved changes.

One suggestion, if your "cancel all events button and close" button is just about cancelling changes, you could try just using the following two commands:

[tt]me.undo
docmd.close acform,me.name[/tt]

which should prevent the before update from running (I think, no changes to save). Else for instance using a form public, mfSave, set it to true in the on load event of the form, then only in the "cancel" button set it to false, and test for it in every event you wish to "disable", for instance in the before update (first line?):

[tt]if not mfsave then me.undo[/tt]

in other events, should there be more invoked by the close operation

[tt]if mfsave then
' perform the routine only when the public is true
end if[/tt]

- of course validation performed in some of the controls "after events will fire when the control looses focus and prior to setting the form public, so it would probably work best if all validation was in the forms before update.

But, as TheAceMan1 also mentiones, what happens if the user hits CTRL+W/CTRL+F4? (this thread, has some suggestions for that too thread702-866344, though in a slightly different context)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top