Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Monitor controls on a form

Posted on 1999-06-28
11
Medium Priority
?
127 Views
Last Modified: 2010-05-02
Is there a way to monitor all controls, e.x. combobox, textbox, and checkbox for events. I have a form with several of these controls that i want code generic events without having to monitor each controls events. Example: have have about 30 text boxes on this form and want to execute code based on the textbox change event. without have to repeat this 30 times for each control.
0
Comment
Question by:rawhide
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 22

Expert Comment

by:ture
ID: 1520255
Putting the textboxes in a control array will allow for one single event procedure for all the textboxes.

Ture Magnusson
Karlstad, Sweden
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1520256
Use a control array, then you only have to code things one time, and the change event would occur for each object in the array. This would probably be the prefered way.

If for some reason you cannot use an array, you could also use a public function or sub routine that each control calls when the change event happens, but you would still have to place code in the change event for each control, but the calling code could be more generic.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1520257
This is why you should use control arrays. Instead of having 30 separate text boxes with 30 events you can have a control array of 30 text boxes and only *one* event that gets an *index* telling it which specific control was selected.

Each element in the control array can still be individually set, but they all share common event handlers.

This can reduce your memory footprint as well.

M

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:rawhide
ID: 1520258
I have these setup as arrays. let me put this another way.
I have an array of textboxes, checkboxes, and comboboxes. i want beable to set a save button to be enabled if any of the values change in any of the controls.
0
 
LVL 22

Expert Comment

by:ture
ID: 1520259
rawhide,


If your array of textboxes is called Text1, then this should work:

Private Sub Text1_Change(Index As Integer)
  Command1.Enabled = True
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 22

Expert Comment

by:ture
ID: 1520260
..of course, you need to make a similar procedure for the checks and combos too.

/Ture
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1520261
If a control array is not viable, you could also create your own user control that has the commen event procedure coded into it.  This is more complex, but it would place all the event code in a single place.
0
 

Author Comment

by:rawhide
ID: 1520262
This is not at all what i had in mind. I will figure something out. Just thought some might have tried this.
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1520263
What exactly did you have in mind?  If you are looking for some global event or API that fires every time an event occurs in a given control type, it doesn't exist.
0
 

Author Comment

by:rawhide
ID: 1520264
Exactly What i was looking for. Maybe i'll just have to create one. didn't want to re-invent it if some one else has already accomplished it. thanks
0
 
LVL 3

Accepted Solution

by:
gajendra earned 300 total points
ID: 1520265
rawhide

I am certain VB does not (inherently) provide for what you are asking? What I am recommending below would be helpful only if you often write end-up rewriting such code.

I would recommend you design a activex control where you can set the change event of all the controls to trigger a common event - which you may handle externally.

It should not be difficult to code the activex to load textboxes and checkboxes etc. depending on txtboxcount, chkboxcount properties.

HTH

gajendra
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question