Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Active control

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
hijay23
Asked:
hijay23
  • 3
  • 3
  • 2
  • +7
1 Solution
 
OtanaCommented:
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
 
nigelroweCommented:
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
 
nigelroweCommented:
It's one off those days!!!!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
hijay23Author Commented:
No i don't want to do this i want any readymade function or API call.
0
 
nigelroweCommented:
I don't think you've got much choice here, but I might be mistaken.
0
 
TimCotteeCommented:
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
 
InteqamCommented:
why do you want such a thing, maybe there is an alternative for what you are trying to do.
0
 
Dave_GreeneCommented:
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
 
InteqamCommented:
the highest but less than the current control tab index , but this wont work if you used a shortcut or mouse.
0
 
OtanaCommented:
yes and if you use tab, why don't you just take the current tab index -1 ?
0
 
InteqamCommented:
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
 
nutwissCommented:
hijay - what are you trying to do? sounds like a validation problem
0
 
rspahitzCommented:
(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
 
TimCotteeCommented:
hijay23, please follow up on this question.
0
 
DanRollinsCommented:
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
 
NetminderCommented:
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

Technology Partners: 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!

  • 3
  • 3
  • 2
  • +7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now