Solved

Active control

Posted on 2001-07-05
17
196 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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.
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…
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…

930 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

13 Experts available now in Live!

Get 1:1 Help Now