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

OnClose event procedure 1

Status
Not open for further replies.

MitchJP

MIS
Feb 17, 2004
43
US
Hello,

The OnClose event procedure applies to forms and reports in Access. Is there a similar event procedure that applies to the database itself? I want to prevent the user from closing the entire database (by clicking the 'X' button in upper right corner, or choosing File>Exit or File>Close).

Any idea as to how I can do this? I can control the closing of the various forms, but I'm not sure how to do it for the actual database itself.

Thanks,
MitchJP
 
Hi!

I use something close to what mstrmage1768 describes in this faq, faq702-1870

Roy-Vidar
 
Thanks!

So basically you assign a boolean to the Cancel event? I'll take a look at it and see.

Thanks,
MitchJP
 
I tried the logic from the FAQ, but it says that The variable Cancel is not defined. Any ideas?
 
You are referring to:

5. In the form's Unload event, place:

Cancel = Not OK2Close

It needs to be in the unload event (one of the events having the possibility to cancel), where the whole encillada would look something like this:

[tt]private sub form_unload(cancel as integer)
Cancel = Not OK2Close
end sub[/tt]

Roy-Vidar
 
Ah, I got it.

I still think there's another issue going on.

I have a form that has a SAVE and CANCEL button (the form allows users to view a record, make changes, and save the changes or cancel the changes). When SAVE or CANCEL are clicked, a macro runs that closes the form, runs some update queries, etc. I think the sequence it screwed up when I added the Cancel logic to the Unload event, as when I click the button, the queries still run, but the form no longer closes and I can't close the form (as Cancel was set to False). I'll have to work through the sequence to rsolve it. I think I'm on the right track though, with your help! :)

Thanks Roy-Vidar!
MitchJP
 
RoyVidar,

Thanks for pointing out that FAQ. This is something that I have always wanted to know how to do but had yet to take the time to research it or ask how to do it.

The code worked great for me. I can't wait until I roll out this version of the database and listen to my users scream. I am going to love it.

THANKS.

Have a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top