Is there a way to "trap" if any field in a frame got or lost focus?

Posted on 2004-04-20
Medium Priority
Last Modified: 2008-03-06
Hi experts,
Let's say there are 10 fields (text, checkbox, radio buttons etc) in a frame within a form.
Is there a method to trap a condition if ANY of the field got a focus (and also lost focus) in that frame WITHOUT doing an individual trap for each field?
thank you,
Question by:spoowiz
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
  • 4
  • 3
LVL 53

Expert Comment

ID: 10875404
In vb.net i know it's possible (see http://www.devcity.net/forums/topic.asp?tid=63679) because the inheritance, but in vb6 I don't think it's possible.

So i'll guess the only possibility is to use it of each control. What you also can do is group your controls. For example rename all your textboxes to the same name, ... so you'll only have 1 event for each type.

Author Comment

ID: 10875453
I am using VB6 :-(
I'm not familiar with using group of controls.
1. How would you define a group of controls on a form?
2. Would you mind giving me an example of how VB code might look like in this case?
thank you,
LVL 53

Accepted Solution

Dhaest earned 500 total points
ID: 10875493
A simple example:
Create a new project, add 2 textboxes to the form. Name them both txtInput
Vb6 will ask if you want to create a control array (just say yes).
Add following code to the application and tab through the application, so both textboxes will lose the focus once.

Private Sub txtInput_LostFocus(Index As Integer)
    If Index = 0 Then
        MsgBox "Your first textbox lost his focus"
        MsgBox "Your second textbox lost his focus"
    End If
End Sub
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10875511
Thank you. The "group" coding is nifty. I'm going to start using it.

Author Comment

ID: 10875554
One more question, if you don't mind. How would I change this if the field was a group control?

Private Sub txtInput_Validate(Cancel As Boolean)  --> (Cancel as boolean, Index as integer) ??
    If Not isValidNum(Me.ActiveControl) Then  ---> Will Me.ActiveControl still reference the correct control?
        Cancel = True
    End If
End Sub

thank you.
LVL 53

Expert Comment

ID: 10875584
Private Sub txtInput_Validate(Index As Integer, Cancel As Boolean)

Normally it should work (me.activecontrol), but it's possible that you'll have to give a reference (the index of the control)

Author Comment

ID: 10875592

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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