Solved

How to determine last textbox with focus.

Posted on 2011-02-18
10
449 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
ID: 34929399
You can use

Screen.PreviousControl.Name

mx
0
 

Author Comment

by:mgmhicks
ID: 34929429
receiving PreviousControl.name is not a member of screen.
0
 
LVL 75
ID: 34929482
But it is ... seem image

something else is up

mx
Capture1.gif
0
 
LVL 10

Expert Comment

by:kdwood
ID: 34929527

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

Regards,

Keith
0
 
LVL 75
ID: 34929554
mgmhicks,
What platform are you in?

mx
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:mgmhicks
ID: 34929657
This is what I see.
Sorry this is what I see.  Using VS 2008
0
 
LVL 75
ID: 34929685
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
ID: 34929798
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
ID: 34929799

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
ID: 35012383
Ended up using lost focus event and using the tag property of the form to know what field to change.

thanks
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

19 Experts available now in Live!

Get 1:1 Help Now