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

Execute VBA code upon quitting application.

Status
Not open for further replies.

djmc

Programmer
Jun 12, 2002
179
CA
How do I get my ms access application to execute vba code when the application exits? (i.e do something before exiting)
 
I don't use Acces, but I think you need the "BeforClose" event. Hope this helped ya out.

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
I don't think there is a before close application event.

The way i usually sort this, is to have a form open and set to invisible when the application opens.

You can set any code you want to run in the on_open event of the form and then put your on_exit code on the On_Close event of the invisible form.

You can get the form to open on startup from the Startup option in the toolbar.

If you need other forms to open with the app, just open them from the original invisible form.

Hope this helps,
sugarflux
 
Hi djmc

Again I don't use Access but for Excel or Word there is a process involving creating a Class module and so on to access application events. There may be something similar for Access.

I think the Excel process is outlined in the FAQ section here. If not there is a description here
and Word is thoroughly covered on the Word MVP site.

If you have no joy here, it may be worth posting in the Access VBA forum? Or is there an Access MVP site?

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Hi djmc,

To the best of my knowledge there are no Access Application Events. There isn't any kind of code module attached to the application - they only exist in databases.

Also AFAIK there is no Database Close Event either but it is possible to mimic one using the technique outlined by sugarflux - but note that the form load on startup is database startup and NOT application startup.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
There are no application events in Access? But I've used the AutoExec macro to execute VBA code at the start when MS Access loads. So I thought that there should be a macro of some sort that executes VBA code before the application closes.
 
Hi djmc,

Where is your code?

Start up Access and open/create a new database. Does your code run at any point?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
The Autoexec macro is a special macro which is executed automatically whenever the database is opened. Therefore I juse include the RunCode action within the macro to call my VBA code. As I was saying before, I am looking for something similar except executing before the application closes.
 
Hi djmc,

I don't wish to be too pedantic, but you are not using an Application event there. You can use an Autoexec macro or set database startup options to run on Database startup, but not Application startup.

As I said in my first post, I don't think it's directly possible to trap database closing but you might be able to mimic it along the lines suggested by sugarflux.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top