Fix Microsoft Access AutoExec Macro Cannot Find a Function
Question details
The user needs an AutoExec macro to find and run a relink function when an Access database opens.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An AutoExec macro uses the RunCode action to call a function such as Reconnect to relink database tables.
- Observed behavior
- Access reports that it cannot find the function called by the macro.
Open the database with startup actions bypassed if necessary by holding Shift while opening it, provided the bypass key is enabled. Identify the function name and arguments in the AutoExec macro's RunCode action.
Make the relink function available to the AutoExec macro
Use this solution when RunCode cannot find the function named in the startup macro.
In Access, press Alt+F11 to open the Visual Basic Editor, then locate the relink procedure in the Project Explorer.
If the procedure is in a form or report module, choose Insert > Module and move the procedure into the new standard module. Name the module something distinct, such as modRelink, using the Properties window.
Ensure the procedure is declared as a Public Function, not a Sub. For a function without arguments, the declaration can start with Public Function Reconnect() and end with End Function. Keep the existing relink logic inside the function.
Open the AutoExec macro in Design View and check the RunCode action's Function Name field. Enter Reconnect() for a function with no arguments, or supply the arguments required by your function. Ensure its name differs from the module name and other Access object names.
In the VBA editor, choose Debug > Compile and resolve any reported errors. Save the changes, reopen the database normally, and check whether AutoExec runs the function.

Check VBA references and trusted content settings
Use these checks if the function is correctly declared but the project still fails to compile or run.
Work with Office Documents in WPS Office
WPS Office is a free, lightweight alternative for everyday documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format compatibility make it easier to move routine work between suites. It does not run Access AutoExec macros or fix Access database errors.

Frequently Asked Questions
Why can't AutoExec find my Reconnect procedure?
RunCode needs a callable public function. In the VBA editor, check that Reconnect is declared as a Public Function in a standard module and that the macro's Function Name field calls it with the required arguments.
Can an Access RunCode action call a Sub?
RunCode calls a function rather than a Sub. Change the procedure to a Public Function in a standard module, then update the RunCode expression and compile the project.
Does the module name matter?
Yes. Give the standard module a name distinct from the function and other Access objects. For example, use modRelink for a module containing the Reconnect function.
How do I check for a missing VBA reference?
Press Alt+F11, choose Tools > References, and look for an entry marked MISSING. Remove it only if it is unnecessary, or select the appropriate available library if the code depends on it.
How can I open the database without running AutoExec?
Hold Shift while opening the database to bypass startup actions, if the database allows the bypass key. You can then inspect the AutoExec macro and VBA code.




