Link to home
Start Free TrialLog in
Avatar of dastaub
dastaubFlag for United States of America

asked on

Determine ControlName which has just received Focus

Current Code:
mName = Trim(TxtName)   'mName is a memory variable   TxtName is a Textbox on a Frame on a Form.
TxtName.BackColor = &HC0C0FF
TxtName.BorderStyle = 1
I have dozens of Textboxes on a Frame; I have lots of redundant code behind each text box.  I have gotten rid of the redundant code
by passing in the name of the textbox to a procedure which contains the previous redundant code behind each text box.  The redundant
code is now:
Call HighLiteMe(TxtName)  'where Txtname is the textbox.

Is there a way to accomplish the following:
Whenever an object on the frame gets focus, if it is a textbox, do this to the text box.  If the program could determine the name of the
Textbox, I would then be able to determine where to send the focus next.


SOLUTION
Avatar of R_Rajesh
R_Rajesh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R_Rajesh
R_Rajesh

dastaub,

why not use the gotfocus event

Private Sub Text1_GotFocus()
MsgBox "i go focus"
End Sub


Rajesh
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops...

>> Create a project and add a timer and as many labels as you like

What I meant to say was:

Create a project and add a timer and as many TEXTBOXES as you like

Idle_Mind


You con monitor all you textboxes  with a single got_focus event...

1. add a single textbox to your form
2. In its properties set its index to 0
3. Now add more textboxes to your form  but do so by copying the original textbox , this will result in an array of textboxes
4. Now add the code to the got_focus event for your textbox control array

Private Sub Text1_GotFocus(Index As Integer)
    MsgBox "textbox " & Index & " has focus"
End Sub
 
the index will tell you what box has focus and you can simply pass the index to your function.
Avatar of dastaub

ASKER

example 1  - inside a mouse up procedure
Set curControl = Screen.ActiveControl
Call HighLiteMe(curControl)

example 2  - inside a procedure
   Set curControl = Screen.ActiveControl
   If TypeOf curControl Is TextBox Then
      If curControl.Name = "TxtMajorComplaint" Then
        Code...
        Code...
      End If
   End If

both codes work, they eliminate the need to hardcode in the name of the active textbox and also can determine the name
of the active text box.  Those were my two goals.  
Thank You.
Avatar of dastaub

ASKER

in my comment date 12/06/2003 08:57 AM PST, I forgot to add that you have to
declare in the general area:
Dim curControl As Control
>> example 1  - inside a mouse up procedure

Don't forget that you can change controls without using the mouse.  Focus may change when you press the TAB key.

Idle_Mind