Solved

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

Posted on 2004-04-20
7
307 Views
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,
Phil
0
Comment
Question by:spoowiz
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
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.
0
 

Author Comment

by:spoowiz
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,
phil
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 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"
    Else
        MsgBox "Your second textbox lost his focus"
    End If
End Sub
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

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

Author Comment

by:spoowiz
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.
0
 
LVL 53

Expert Comment

by:Dhaest
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)
0
 

Author Comment

by:spoowiz
ID: 10875592
thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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 …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

839 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