Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Function from Macro Design In Access

I have written some sql queries, some sub procedures and have some saved imports.

Now I am trying to use the Macro Design in Access to provide a run button which will run these objects sequentially.

However I dont see any command for running a sun procedure, I can see OpenVisualBasicModule and Runcode.

OpenVisualBaicModule is only opening my sub procedures and Run Code is asking for a function only.

I created a function with all the sub procedure call inside. But thats not working while individually all of them work.

Any suggestion what to do.

like image 986
SAM244776 Avatar asked Jun 07 '26 11:06

SAM244776


1 Answers

Make sure your VBA code is placed inside a Function (not a SUB, that won't work). Create your function like:

Function DoSomething()
  'Do your stuff
End Function

Or if you want to execute a Sub, just create a Function that calls your sub, like:

Function DoSomething()
   Call YourSub()
End Function

Inside the Macro Design, add the 'RunCode' action (Macro Commands > RunCode) and call your function:

DoSomething()

And voila, you're done.

like image 51
Rob van Meeuwen Avatar answered Jun 10 '26 09:06

Rob van Meeuwen