Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click event in seperate module

Status
Not open for further replies.

steijssen

Programmer
Mar 25, 2001
92
BE
Hello,

I want to put a long list of button_click() events in a seperate module. Is this possible? If so, how? I make the subs public, use the right reference for the fields in my statements.. Do I need to enter something else than:

Public Sub SomeButton_Click()
...
End Sub

Like Public Sub Form1_SomeButton_click() instead of just SomeButton_Click? (I know that one doesn't work, tried it already)

Thanks for helping me out on this!
 
Not unless you either write code in each standard event handler to call your public subs (defeats the object) or subclass the application event handler and redirect the events from there (plenty of source code available on the web)
 
What I would suggest is to leave the event handlers in the form to which the button applies. However, you can put all of your code into a module, and all the event handler does is call that routine. This also allows you to have different buttons on different forms actually execute the the same code. Here's a quick example.

In a Module
------------

Public Sub TheButton1Logic ()

<The applicable code for your application>

End Sub


In Form 1
---------

Private Sub cmdButton1_Click

TheButton1Logic

End Sub

In Form 2
---------

Private Sub cmdButton1_Click

TheButton1Logic

End Sub

and of course you can extend that as your needs require Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top