Solved

How to determine last textbox with focus.

Posted on 2011-02-18
10
446 Views
Last Modified: 2012-05-11
I have a form that looks like a keyboard, on the form is about 3 panels.  Depending on what the user is doing determines what panel is visible and then, what textboxes are available.  The idea being hit clicks on name text field lets say, and then hits the a, b,c, etc... on the keyboard.  I need to know what field he just came from so I know what fields to put the keyboard items into.  I hope that makes sense.

thanks
0
Comment
Question by:mgmhicks
10 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
You can use

Screen.PreviousControl.Name

mx
0
 

Author Comment

by:mgmhicks
Comment Utility
receiving PreviousControl.name is not a member of screen.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
But it is ... seem image

something else is up

mx
Capture1.gif
0
 
LVL 10

Expert Comment

by:kdwood
Comment Utility

I don't think he is in Access.  I believe he is in VB.NET

Regards,

Keith
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
mgmhicks,
What platform are you in?

mx
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mgmhicks
Comment Utility
This is what I see.
Sorry this is what I see.  Using VS 2008
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
You are not in Access.  I would move this Question to the VB.Net / VB zone.

I don't know the answer ... sorry.

mx
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Use a COMMON handler for ALL of your TextBoxes by listing them all after the "Handles" keyword.

Something like:
Public Class Form1

    Private LastTextBox As TextBox = Nothing

    Private Sub TB_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
        LastTextBox = DirectCast(sender, TextBox)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not IsNothing(LastTextBox) Then
            LastTextBox.SelectedText = Button1.Text
        End If
    End Sub

End Class

Open in new window


Note that if your buttons have the Text to be inserted as the caption of the button, AND all of the buttons do the exact same thing, then you can make all of them fire the same handler in the same way as the TextBoxes above:
Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
        If Not IsNothing(LastTextBox) Then
            Dim btn As Button = DirectCast(sender, Button)
            LastTextBox.SelectedText = btn.Text
        End If
    End Sub

Open in new window

0
 
LVL 2

Accepted Solution

by:
bobHacker earned 500 total points
Comment Utility

Hello,

In the "Field"/control's exit event set up a variable with a value as to where you were.
Set the variable to the proper scope.
...then you will now where you came from.

b+  
0
 

Author Closing Comment

by:mgmhicks
Comment Utility
Ended up using lost focus event and using the tag property of the form to know what field to change.

thanks
0

Featured Post

Free Trending Threat Insights Every Day

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.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

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

10 Experts available now in Live!

Get 1:1 Help Now