Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ms-access: doing something on database open

Tags:

vba

ms-access

is it possible to run a sub or function as soon as the user opens an access database file? if so, how?

like image 233
Alex Gordon Avatar asked Jun 22 '10 16:06

Alex Gordon


2 Answers

Create your function:

Public Function DoSomething()
    ' do stuff '
End Function

Then create a macro with the run code action which calls your DoSomething function. Name the macro autoexec. Then, every time the data base starts up, it will run your autoexec macro.

Another thing you can do is set a form to open whenever the database starts. You could then call your DoSomething function from a form event (on open, or on load).

Choose one of those approaches. Either way, if you ever want to start the database without DoSomething running, hold down the shift key as the database opens to bypass your automatic startup routine.

like image 101
HansUp Avatar answered Nov 04 '22 01:11

HansUp


You could open a hidden form on start up like in Access 2007 Startup. This is also possible in older Access version.

You may use this hidden form for logging or other 'system'-related tasks.

like image 20
FloE Avatar answered Nov 04 '22 01:11

FloE