Solved

Active control

Posted on 2001-07-05
17
204 Views
Last Modified: 2012-06-27
Dear Friends,

 i have to find out the last active control on the form how to do that any function is available to find out that. Like suppose i am entering values in Text1 after pressing tab the cursor goes to next control i.e. Text2
now in Text2.GotFocus() event i want to find out the last
active control how to do that. In this case Text1 is the last active control.

Plz help me.

regards.
Jay
0
Comment
Question by:hijay23
[X]
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
  • 3
  • 3
  • 2
  • +7
17 Comments
 
LVL 11

Accepted Solution

by:
Otana earned 50 total points
ID: 6255486
you could put this in the lostfocus event of each control:

LastControl= Name-Of-Control

and make LastControl a public variable

But if you have many controls, it's quite a job to do so.
0
 
LVL 3

Expert Comment

by:nigelrowe
ID: 6255550
Maybe you could set a global variable to the name of the control which has just lost the focus, something like...


Option Explicit
Private lastfocus As String

Private Sub Text1_GotFocus()
    MsgBox lastfocus
End Sub
Private Sub Text2_GotFocus()
    MsgBox lastfocus
End Sub

Private Sub Text1_LostFocus()
    lastfocus = "Text1"
End Sub
Private Sub Text2_LostFocus()
    lastfocus = "Text2"
End Sub
0
 
LVL 3

Expert Comment

by:nigelrowe
ID: 6255558
It's one off those days!!!!
0
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

by:hijay23
ID: 6255649
No i don't want to do this i want any readymade function or API call.
0
 
LVL 3

Expert Comment

by:nigelrowe
ID: 6255747
I don't think you've got much choice here, but I might be mistaken.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6255757
There isn't a ready made function for this. Each control is autonomous within its container it is only responsible for events which occur whilst it is getting/has/losing focus you CANNOT infer the previous control from the current one in any way as the current control does not even know about the existence of any other controls unless it is bound to them in some fashion. You HAVE to follow one of the methods already suggested in some way in order to achieve your desired result.
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 6255803
why do you want such a thing, maybe there is an alternative for what you are trying to do.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6255824
You could try looping through each control on the container and pull out the one with the highest tabindex

For each ctl in form1.controls
  if ctl.tabindex > highindex then
     highindex = ctl.tabindex
     highname  = ctl.name
  end iff
next  
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 6255834
the highest but less than the current control tab index , but this wont work if you used a shortcut or mouse.
0
 
LVL 11

Expert Comment

by:Otana
ID: 6255858
yes and if you use tab, why don't you just take the current tab index -1 ?
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 6255873
lol, right


always think simple.
:o)

but i think there can be a gab between, i mean you can have two controls only on a form , one with 0 tab index and the other with a 4 tab index ( i am not sure). :o(
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6256144
hijay - what are you trying to do? sounds like a validation problem
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6256294
(From MS Help)
ActiveControl Property

Returns the control that has thefocus. When a form is referenced, as in ChildForm.ActiveControl, ActiveControl specifies the control that would have the focus if the referenced form were active. Not available atdesign time; read-only atrun time.

--
However, I'm not sure how you would implement something like this in your case without creating an "endless" loop that checks for it.
After all, as soon as you click on something else, the control loses focus and is no longer active!
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6312040
hijay23, please follow up on this question.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7148107
Hi hijay23,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: Otana and TimCottee

hijay23, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7182120
Per recommendation, force-accepted.

Netminder
CS Moderator

TimCottee: points for you at http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328902
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

732 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