By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,478 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,478 IT Pros & Developers. It's quick & easy.

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

P: 230

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?

Jan 6 '12 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 10K+
P: 12,421
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.
Jan 6 '12 #2

Seth Schrock
Expert 2.5K+
P: 2,951
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.
Jan 6 '12 #3

P: 759
Or, from the OnLoad event, apply the routine for yours button click event.
Expand|Select|Wrap|Line Numbers
  1. Call YourButtonName_Click
Jan 7 '12 #4

P: 103
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.
Jan 7 '12 #5

Expert Mod 15k+
P: 31,709
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. :
Expand|Select|Wrap|Line Numbers
  1. Private Sub {EventA}()
  2.     Call {CommonSub}()
  3. End Sub
  5. Private Sub {EventB}()
  6.     Call {CommonSub}()
  7. End Sub
  9. Private Sub {CommonSub}()
  10.     ' Common code
  11. End Sub
As opposed to :
Expand|Select|Wrap|Line Numbers
  1. Private Sub {EventA}()
  2.     Call {EventB}()
  3. End Sub
  5. Private Sub {EventB}()
  6.     ' Common code
  7. End Sub
If you later need to maintain this code you will be glad you managed it the former way ;-)
Jan 8 '12 #6

Post your reply

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