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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Click event of form to be executed first before control event

Status
Not open for further replies.

MooYai

Technical User
May 16, 2003
12
DE
Hi all,

I have a form with lets say 20 text boxes txtbox1 to txtbox20 and I would like to run the code under Form_Click or detail_Click instead of running the code for the control event.

Does anyone have an idea hoew to do this

Thx
 
In the On Open event of the form in question, try putting your code there.

HTH

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
 
Maybe I'm misunderstanding the question, but if you put your code in the Form or Detail Click event INSTEAD of the control(s) event, that would be the only way the code would be executed?

A sample of the code you want to run might be helpful.

< M!ke >
 
Sorry for not being more specific.
What I want to do is following:

Everytime I click on one of the textboxes I want to run the same Sub. So in order not to put the same sub into all 20 txtbox1_Click to txtbox20_Click I thought I can give the Form click priority over the control click then I would save coding and it would look nicer. I would not have a module with 20 or more txtboxZ_Click Subs all calling the same code.
Hope this explains it a bit better.
Thx for answering my question

 
All events are tied to the objects that own that event. Every control is its own object with its own events (and properties and methods), so do to what you want to do would require sub-classing all of the controls, trap the event message, and based on the event message, either pass it back to the control for normal handling, or throw it away and raise the corresponding event for another object. Although doable, it would in no way be worth the effort.

A far better approach is to have the normal event handlers set up, and from within the event handler, call the common subroutine.

Sub Text1_Click
ExecGlobalClickRoutine
End Sub

Sub Text2_Click
ExecGlobalClickRoutine
End sub

and so forth. Then write your ExecGlobalClick routine.

Public Sub ExecGlobalClickRoutine
....
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
That's the way I did it, but I wanted to avoid having twenty times this

Sub Text1_Click
ExecGlobalClickRoutine
End Sub

But I thought there is an way to sort of ignore the control click and execute the form click instead.

Never mind anyway.
Thx very much for taking your time.
 
Nope. Cajun's right. One of the joys/curses of object-oriented programming...

< M!ke >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top