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

how to put a code in to the on click event of the command button?

P: 3
i want to print my access form page with its details. i have got the following code and now i want to put this code to the on click event...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub CommandBtn_Click()
  2. Dim MyForm As Form
  3.     Set MyForm = Screen.ActiveForm
  4.     DoCmd.SelectObject acForm, MyForm.Name, True
  5.     DoCmd.PrintOut
  6.     DoCmd.SelectObject acForm, MyForm.Name, False
  7.  
  8. End Sub
Apr 21 '14 #1
Share this Question
Share on Google+
2 Replies


Seth Schrock
Expert 2.5K+
P: 2,951
It looks like it is already in the OnClick event based on the "_Click" at the end of the procedure name. If you go into design view on the form, click the button that you want this code to be behind, click on the events tab of the property window (press F4 if not visible) and then click inside the OnClick event box. You will see an ellipsis button (three dots). If you don't see Event Procedure inside the OnClick event box, then when you click the ellipsis button, you will be asked what type of event you want to build. I can't remember off hand if it says Code Module or Event Procedure, but the other options are Macros and Expression Builder and you don't want these. It will then create the event sub and you can then copy the code into it.
Apr 21 '14 #2

zmbd
Expert Mod 5K+
P: 5,397
[event procedure]
will be in the proper event property of the control for VBA.

Please review this link for some options that should be set along with some basic troubleshooting:[*]> Before Posting (VBA or SQL) Code
Apr 21 '14 #3

Post your reply

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