Solved

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

Posted on 2004-04-20
7
303 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

773 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