"KenR" <(E-Mail Removed)> wrote in message
news:71B2A5B3-D534-4F99-830F-(E-Mail Removed)...
>I didn't copy the code from a module, it was posted, in its entirety, in
>this
> forum.
>
> However, I'm happy to use a different method... whatever will work
>
> I already have a hidden form running at all times in the database, so I
> can
> include any necessary code in the form's unload event. The housekeeping
> tasks I need to perform may require some user involvement, so I can't just
> attach the tasks to the event.
>
> I would like to cancel the close event if the user didn't exit using the
> button I provided. However, I don't know how to "cancel the unload," as
> you
> referred to it. Can you help with that?
Here's a way to manage it: Put an unbound checkbox control named
"chkOkayToClose" on the hidden form, with the default value False. In your
Exit command button's Click event, after you've taken care of your
housekeeping but before issuing your Quit command, add the line
Forms!YourHiddenFormName!chkOkayToClose = True
(changing the form name appropriately). In the Unload event of your hidden
form, put an event procedure like this:
'----- start of code -----
Private Sub Form_Unload(Cancel As Integer)
If Me!chkOkayToClose = False Then
MsgBox _
"Please click the Exit button to close this application.", _
vbExclamation, _
"Exit Using Button"
Cancel = True
End If
End Sub
'----- end of code -----
That ought to do it. Bear in mind Armen Stein's warning about global
variables. By the time you get to the hidden form's Unload event, they will
probably already have been cleared.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)