How to programmatically click a button on another form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • landolakes
    New Member
    • Aug 2007
    • 4

    How to programmatically click a button on another form

    Hi.
    I have two forms. The first, designed some time ago, is just a report request form and has a combo box to select a workorder, click "Run Report" (cmdRunReport), and the user gets a status report on this workorder. There's a lot of code in the cmdRunReport module.

    Now I have a new form for a different use, but it also happens to have the same workorder selection field. The head user just said, golly, can we get that status report to run off this form? I thought it would be simple.

    I have a button on the new form with the intended goal to run the report. I can't get the code behind this new form's button to "click" the Run Report button on the old form. I can't seem to find help about it (probably not searching using correct terms). Can anyone give me the one-liner on how to run the cmdRunReport_On Click routine on the old form from the new form?

    I know there are a lot of complex ways to fix this, but I'm really interested in simply running that code from a different form.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, landolakes.

    Change private sub cmdRunReport_On Click declaration to public.
    Then while the form is open
    Code:
    [<Form module name>].cmdRunReport_OnClick

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      If you give us the names of everything and where (the module) you want to call it from I'll try to knock something up for you.
      Having said that - a better way to do this would be to have the code that does the work in a standard module with a standard procedure name and then call THAT procedure from both of the forms. The way you're proposing, though it is possible, is highly unrecommended.
      I will provide the line of code if I can though notwithstanding the advice if you still feel you need it.

      Comment

      • landolakes
        New Member
        • Aug 2007
        • 4

        #4
        Thanks FishVal!
        That was the tidbit I needed: changing from private to public. those headings are automatic and I forgot to even think about it. But of course.

        And NeoPa, yes, your suggestion is the more proper way to handle, and would be how I would do it if I knew about this at the time the original report was created and that submission form was designed. But I personally don't want to spend the time re-writing the code as a procedure in the module section, testing out both forms, etc, when all I needed to do minimally is change Private to Public on the form that users have been using for a long time, and then one line of code in my new procedure. I hope that if I have to hand this off to someone else to maintain, they will be able to figure it out. Thanks though.

        I appreciate the quick responses. My boss will be happy too.

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          You are welcome.
          Keep your boss happy. :)

          Regards,
          Fish

          Comment

          Working...