424,289 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,289 IT Pros & Developers. It's quick & easy.

VBA to run multiple Public functions/Modules

100+
P: 100
I have 3 modules that I trigger individually with a command button to run the code. What I'm curious is there a way for me to run the 3 different modules one right after the other?
Currently there is 2 buttons that open up the same form but with different filtering and a third button that opens another form.

If needed I could add the code behind each button, but I'm hoping its not. It is lengthy.
Nov 28 '18 #1

✓ answered by Rabbit

In the code for the button, call the 3 other functions.
Expand|Select|Wrap|Line Numbers
  1. Sub ButtonName_Click()
  2.    Call FunctionNameA()
  3.    Call FunctionNameB()
  4.    Call FunctionNameC()
  5. End Sub
  6.  
The bigger issue you should be working on is why the code takes 3 days and 12 hours to run. Most likely something is running extremely inefficiently and if you fix the inefficiency, you can cut the run time down to minutes.

Share this Question
Share on Google+
6 Replies


twinnyfo
Expert Mod 2.5K+
P: 2,888
DJ,

Your question is a bit confusing, as you talk about triggering modules. I think I understand what you mean there, but then you mention opening different forms.

One does not trigger modules, one triggers procedures within modules. As long as those procedures are public, they can be executed from anywhere at any time, in or out of sequence. Perhaps we need a bit of clarification on this one.

However, I think the general answer to your question is “yes”.

Hope this hepps.
Nov 28 '18 #2

100+
P: 100
That's good, When I'm back in front of the database I will post the code of each module. What I truly want to do is click a button and have it trigger function 1, and once this one is complete it will trigger function 2 and so one. Each one of these function exports several reports of a certain report that meet certain criteria.

I kind of goofed in my question. I have macros(I know the wrong way of doing) that open a filtered form. Then on that form I have a button that triggers the function to export reports that meet certain criteria. As it stands now everything works perfectly, I just have to do it individually and one of the function runs for 3 days straight, the other 2 can be done in less than 12 hrs.
Nov 28 '18 #3

Rabbit
Expert Mod 10K+
P: 12,303
In the code for the button, call the 3 other functions.
Expand|Select|Wrap|Line Numbers
  1. Sub ButtonName_Click()
  2.    Call FunctionNameA()
  3.    Call FunctionNameB()
  4.    Call FunctionNameC()
  5. End Sub
  6.  
The bigger issue you should be working on is why the code takes 3 days and 12 hours to run. Most likely something is running extremely inefficiently and if you fix the inefficiency, you can cut the run time down to minutes.
Nov 28 '18 #4

100+
P: 100
Wow a lot easier than I thought. This is a very complex database created by another programmer and its been taking me a long time to chip away at it, but getting there. Some of the time is, there are thousands of reports to export out. I usually have it run on the weekends while i'm off of work.
Nov 28 '18 #5

NeoPa
Expert Mod 15k+
P: 31,186
I'm just going to go ahead and mark Rabbit's post as the Best Answer. It perfectly answers the question posed.
Nov 28 '18 #6

Rabbit
Expert Mod 10K+
P: 12,303
Feel free to create a new thread for this but figuring out the purpose of exporting thousands of reports and addressing that need in a different way help the run time tremendously. I suspect no one's actually looking at these thousands of exports and it's being used for a different purpose. Eliminating this export by serving the ultimate end goal in another way will be a huge time saver.
Nov 29 '18 #7

Post your reply

Sign in to post your reply or Sign up for a free account.