This error can happen when you try to run a sub routine in VBA MSACCESS immediate window.
This can happen if you tried to create a routine in a class module instead of a module.
Notice how the test code works fine in module 1.
However when the same sample code is run in class1 the sub routine fails and generates the error: Compile Error: Sub or Function not defined..
Also you can get the Sub or Function not defined error message when you incorrectly call the sub routine. For example if you make a spelling error or have a typo in your call in the immediate window, the sub or function not defined error will appear as shown below. The sub routine is named ‘test’ but the calling code in the immediate window calls ‘test2’.