Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing focus after Alt Tab

Status
Not open for further replies.

jlisota

Programmer
Mar 7, 2005
6
US
I am currently having a problem with one of my applications where when you alt tab to a different application and then alt tab back the policy number should have focus but does not. So the question would be is there a way to set the focus on a single field after alt tabbing between applications.
 
If you want a specific field to get focus every time you return to the application I would just use the gainFocus event of the main form to give focus to the the field.
 
This application is coded in VB5 and I do not see a gainFocus. Is there an event which gets called when you bring the original application back to the front or is it always active in the background?
 
Neither gotfocus nor activate do not fire when you swith between apps.

One solution would be using API Window relating functions.
The other way is to set keypreview of your form to True, intercept Alt/Tab in Form_KeyDown event and set focus to your policy number field in this event. I did not figure out how to intercept the combination but for the Alt key it should like that:

Option Explicit

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim blAltDown As Boolean

blAltDown = (Shift And vbAltMask) > 0

If blAltDown Then
txtPolicy.SetFocus
End If
End Sub

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top