VBA to run multiple Public functions/Modules

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJRhino1175
    New Member
    • Aug 2017
    • 221

    VBA to run multiple Public functions/Modules

    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.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    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.

    Comment

    • DJRhino1175
      New Member
      • Aug 2017
      • 221

      #3
      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.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        In the code for the button, call the 3 other functions.
        Code:
        Sub ButtonName_Click()
           Call FunctionNameA()
           Call FunctionNameB()
           Call FunctionNameC()
        End Sub
        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.

        Comment

        • DJRhino1175
          New Member
          • Aug 2017
          • 221

          #5
          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.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I'm just going to go ahead and mark Rabbit's post as the Best Answer. It perfectly answers the question posed.

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              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.

              Comment

              Working...