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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If all conditions are not met, cancell a form close 1

Status
Not open for further replies.

mrgrogro

Technical User
Jan 8, 2005
58
0
0
US
I have a form that has 36 checkboxes. (three possibilities for each of twelve items) Depending on which box is checked, a text box is updated to "Safe", "At Risk", or "N/A". Ive noticed that not every opertor has been diligent in making a selection for each item. I'd like to change that. I was going to use an if statement in the On Close event to check the resultant text boxes and if the value there was null, I'd have a message box appear indicating that that item needed to be evaluated. I did that for each of the 12 lines but this really doesn't solve my problem. I get a message box that advises me to make a selection but when I click okay, the form closes. Can someone help me out with another line of code that cancells the close and if possible places the focus at the corresponding check box? As always, I am already in your debt.
 
You can do like this....

In form design view
In Properties Window, Select "Format" Tab
Scroll Down Untill you see "Close Button"
Set "Close Button" Property to "No"

Select "Others" Tab
Set "Modal" Property to "Yes"

Now there is no way the user can Close the Form

Place a Command Button on the Form
Code the On_Click Event of the Command Button in such a way that the "docmd.close acform, me.form.name" is executed only when all your conditions are satisfied.

Hope this helps you....
Regards,
 
Thanks handsonaccess! I had already removed the close button and was doing that from a command button on the form. Your post made me think of something else. I think I'm going to make the close command button visible only if all the criteria are met. Can you feel the synergy now? Thanks again!!!!!!
 
Erm - are your users totally unaware of standard windows shortcuts like ctrl+F4/ctrl+w

The technique of only have the close button visible - hm - see first comment;-)

Rather than try to cancel the close, I think the usual approach is to disallow save - which means doing validation in the before update event of the form, then just cancelling the save through; Cancel = True (and/or do a Me.Undo). Depending on wished functionality, there can be a couple of steps more, though ...

Isn't this more a forms question (forum702) and not an Access Modules/VBA Coding issue?

Roy-Vidar
 
Well the answer to the thread was based only its context and he will have to set Form KeyPreview property to Yes and trap the Alt/Ctrl+F4 and Ctrl+W Keycodes.

As for saving - Putting a validation before saving is the best method - No doubth with that!!!

I Agree with Roy-Vidar

Thanks,
 
There is an Unload event of the form that can be Canceled...

If the form is unbound, BeforeUpdate will never fire up, so this is the place to check the data.

However, make sure you're not trapped, otherwise you may need Ctrl+Alt+Del to quit the application...


HTH



[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top