Running a Module When an Access database is opened

J

J_Garcia

I am extrememly new to any of this and I have seemed some answers to this
question but they were not very descriptive. I am trying to run a module when
access is opened, and I was trying to do so by using a macro named autoexec.
Can anyone give me a very detailed answer to this question?

Thanks in advance,
J
 
A

Albert D. Kallal

Sure, but be aware that you can't run a module, but run code *inside* of a
module.

A module in ms-access is a collection of code and routines that you can
execute. So, in each module you create, you would typically place INSIDE of
that module MORE then one piece of code to execute.

So, for example, I have a bunch of code for merging data with word. So, I
created a module called WordMerge, and in side of that module there is many
routines (call subroutines and functions).

So, you can't just put code in a module. For example the follwing will say
hello

msgbox "hello, how are you!"

However, that lone line of code needs to be part of a routine. So, you could
place the following in a module


Public Function MyTestHello

msgbox "hello, how are you"

end sub

save the module. Now, in your autoexec macro, you can call that code using

runcode

And, in the function name, you put in

MyTestHello()
 
K

Ken Snell [MVP]

You would use a macro named AutoExec. In that macro, use the RunCode action.
The action should call a function that you've put in a public module. That
function should then call the code that you want run.
 
J

J_Garcia

Thanks very much, it makes perfect sense now. Thanks for taking the time to
explain in detail.
 
Top