"RunCode" macro and function problems

BenH

Registered User.
Local time
Today, 14:35
Joined
Oct 31, 2008
Messages
25
I have some VBA in a procedure that is an event procedure from a form. I want this code to run when Access opens, so I have created a macro with a RunCode event, but this required a function. I've never worked with functions.
I added the following just above my current procedure;

Public Function RunAuto()
Call MyEventProcedure
End Function

And I ensured the entry on the Macro referred to "RunAuto().
However, it won't work.
Says it cannot find the function.
Any advise?
Do I need to create a new module? I tried that, and added the same code, but now it says "compile error sub or function not defined"
Help!
 
No, I don't. I need to the use the DB for other purposes and so an autoexec macro would not be suitable. Other users use it also.

You can run a macro on startup via a shortcut icon with a command line option of /x, and this is my preferred option and I've set up the scheduled task to do this, and it works fine.

The problem is not that I cannot get the Macro to start, the problem is that the RunCode part of the macro cannot find my function (I fail to see how using an AutoExec macro would resolve this).

Thanks.
 
You've put the code in a form module. The code isn't firing because it is out of scope and needs to go in a global module. If you want to run a function in a form module then form needs to be fully opened and a full reference to the function written.

You can also run a command in a db using DoCmd.Run
 
Do I need to create a new module? I tried that, and added the same code, but now it says "compile error sub or function not defined"
Help!

Yes you do, however if transferring the code to a new module has caused issues then chances are it's referring to something like form controls, etc.

Can you post the code from the module?
 
Thanks, I've amended the OnClick procedure in the Form module to simply call another sub procedure in a seperate module, and put the the function in this new module. This works better. Thanks.
 
P.s. when I'd tried the 'new module' solution before, I was simply creating a new module just for the function itself - but said function was trying to 'call' the onlcick procedure from the form - which I think is why it was not having it.

Now, the code I want to run, and the function calling it, are in the same module, and the onclick procedure for the form just calls the code.
 

Users who are viewing this thread

Back
Top Bottom