Catch User Click on 'X' button

G

Guest

We want to capture a user click on the 'X' to close access and run the
following code to compact the database every exit. I can only hope that there
is a way (maybe API call) that I can use to capture this. We have to force a
compact on exit.

Thanks in advance
Rossco

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub
 
D

Dirk Goldgar

Rossco said:
We want to capture a user click on the 'X' to close access and run the
following code to compact the database every exit. I can only hope
that there is a way (maybe API call) that I can use to capture this.
We have to force a compact on exit.

Thanks in advance
Rossco

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I'm a little confused. That code will only work in Access 2000 or
above, but those versions of Access have a compact-on-close option
(Tools -> Options..., General tab, Compact on Close) that will do this
with no code on your part. Is it that you are afraid the user will
reset the option? You could take away the Options... menu option.\

You can't actually capture the click on the X ("close window") button of
the Access application window. If you really need to trap the
application's exit, open a hidden form at startup and use that form's
Close event to run your code. But I don't see that you need to for what
you're trying to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top