Tuesday 15 September 2015

ms access - How to bind VBA code to a click? -


I have created a graphical navigation system so that the user can easily find the record he / she wants. I am using it in many ways, and since I am going to use it on any other form, I want to separate the code in a class instead of copying the VBA code. I can improve the code, instead of making similar changes on all forms.

How it works now:

  Like new v new set of clsNav v.button1 = Me.button1 set v.button2 = Me.button2 v.init < / Code>  

and in v.init, I want to set all events just like clicks. Therefore, when a user clicks the 1 button, he should run a specified method.

How can I do this?

The occurrence of button clicks will look like this

  private sub button 1_kill () 'Your code ending sub   

And to be able to reuse the code located within the code found near the related forms, you only write a sub in a separate module And then call it in the event.

  Private sub button 1_Click () Call MySub () End Sub 'This is in a module Private sub-mesib ()' Your code and all   

Until now, the code does not use the specific control of that form to run it, it works. If you have to type this code, then it is a matter of controlling its code instead of calling its code from its name example, let's say that when we press our buttons If you click on it, it updates the text box with today's date. The text box has a different name on each form txtDate1 on form1 and txtDate2 On form2 . Then how will this look

  'Form 1 Button Personal All Button 1_Click () Call MySub (txtDate1) End Sub' Form 2 Button Personal Subtotal 2_Click () Call MySub (txtDate2) End If you are trying to do this during your time of running  

have a good place to start It sounds like I can not imagine a situation where it is worth the effort.

No comments:

Post a Comment