Run vba code when database opens

R

Rich Mogy

I would like my vba script to run when my database opens. In Excel, I can
create a sub workbook_open when automatically executes when the workbook is
opened. I would like to do the same in access. Please help

Rich Mogy
 
R

RoyVidar

Rich Mogy wrote in message
I would like my vba script to run when my database opens. In Excel, I can
create a sub workbook_open when automatically executes when the workbook is
opened. I would like to do the same in access. Please help

Rich Mogy

There are two ways I remember of the top of my head

1 - create a macro, and name it AutoExec. Use the RunCode action, and
specify the *function* you wish to run. If what you have is a sub, just
make a small function to call it
2 - in Tools | Startup - specify a form you wish should be the form
that
opens when you open the db. In the on open/on load event of this, fire
off this code of yours.
 
G

George Nicholson

Create a macro called AutoExec. Have it call your VBA code. AFAIK, there is
no magic name that you can apply to a VBA routine to have it start
automatically, but there is a magic name for macros. AutoExec is usually the
only macro in my mdbs.

Another approach would be to use Tools>Options to establish a Startup form
and have that Form's Open event call other code. I don't like doing this
because it turns what is usually just a cosmetic "splash" screen (at least
in my apps) into something critical. But that's just a personal preference.

HTH,
 
R

Rich Mogy

That did the job -- thanks -- I chose option 1
RoyVidar said:
Rich Mogy wrote in message


There are two ways I remember of the top of my head

1 - create a macro, and name it AutoExec. Use the RunCode action, and
specify the *function* you wish to run. If what you have is a sub, just
make a small function to call it
2 - in Tools | Startup - specify a form you wish should be the form that
opens when you open the db. In the on open/on load event of this, fire
off this code of yours.
 
R

Rich Mogy

That did the job, thanks. BTW -- what is AFAIK
George Nicholson said:
Create a macro called AutoExec. Have it call your VBA code. AFAIK, there
is no magic name that you can apply to a VBA routine to have it start
automatically, but there is a magic name for macros. AutoExec is usually
the only macro in my mdbs.

Another approach would be to use Tools>Options to establish a Startup form
and have that Form's Open event call other code. I don't like doing this
because it turns what is usually just a cosmetic "splash" screen (at least
in my apps) into something critical. But that's just a personal
preference.

HTH,
 

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