Solved

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

Posted on 2004-04-20
7
290 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Author Comment

by:spoowiz
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now