How do you open a form, and Automagically click a button?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    How do you open a form, and Automagically click a button?

    Hi,

    I am running into an issue with a MS Access form. When I open my form I have a lot of text boxes that will update once a button on the form is pressed. (takes about 30 seconds to run through code and update), but I want to do Away with the button, and make it to when you open the form it automatically clicks that "hidden" button and populates data.

    I have not been able to make it work for some reason. So, how do you click a button when you tell the form to load? Is their a special spot?

    Thanks,
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You don't have to. The button click does only one thing, trigger the function linked to the button click. You can forego the button click and just copy the code into the OnLoad event of the form.

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      Just move the code from the OnClick event on the button to the OnLoad event of the form. You can then delete the button instead of just hidding it. If the button is supposed to run a macro, you can put that macro into the OnLoad event.

      Comment

      • Mihail
        Contributor
        • Apr 2011
        • 759

        #4
        Or, from the OnLoad event, apply the routine for yours button click event.
        Code:
        Call YourButtonName_Click

        Comment

        • Brian Connelly
          New Member
          • Jan 2011
          • 103

          #5
          I agree with Seth. You may not want to remove the button for future use. I would call the button method from th OnLoad event, although Rabbit is correct by placing the code in the OnLoad. Either way should do the trick.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            I generally advise where a situation occurs that requires the same code to be run from more than one event, that a separate procedure is designed to handle the common code rather than either of the event procedures be called from the other.

            IE. :
            Code:
            Private Sub {EventA}()
                Call {CommonSub}()
            End Sub
            
            Private Sub {EventB}()
                Call {CommonSub}()
            End Sub
            
            Private Sub {CommonSub}()
                ' Common code
            End Sub
            As opposed to :
            Code:
            Private Sub {EventA}()
                Call {EventB}()
            End Sub
            
            Private Sub {EventB}()
                ' Common code
            End Sub
            If you later need to maintain this code you will be glad you managed it the former way ;-)

            Comment

            Working...