View Full Version : how to execute a module from a macro?


Sleekmac
10-17-2006, 09:59 AM
I have a large macro that calls a bunch of queries, and somewhere in the middle I need to put a piece of VBA code that is stored in a module.
So my macro looks like this:
openQuery
openQuery
openQuery
openQuery
openModule
openQuery
openQuery
openQuery

The module is a blend of select and action queries with loops, etc. all taking place on a table contained in the database. When I run the macro, it is not executing the Sub in the module. I'm trying to decipher the MS Access help, and it looks like the openModule function only opens the module in Design mode, which I cannot think of one real-world application for. How do I go about opening the module and then Running it?
Thanks in advance,
Don

pbaldy
10-17-2006, 10:11 AM
Try using RunCode

Sleekmac
10-17-2006, 11:02 AM
runCode seems to be looking for a function rather than a sub. Is this as simple as creating a function in another module that in turn calls the sub?
Can you suggest an easy way to create a public function that points to a sub? Sorry, I am pretty new to VBA, so pretty clueless.

pbaldy
10-17-2006, 11:38 AM
You can probably just change the sub to a function. It would need to be public, in a standard module.

Sleekmac
10-17-2006, 12:48 PM
You are a frickin genius! Thanks again. :)