Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
Independent Software Vendors: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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