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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect where focus is moving to in LostFocus

Status
Not open for further replies.

drewson

MIS
Jun 3, 2003
50
US
Is there any way to detect which control the focus is moving to in the LostFocus of the control that is losing focus?
 
Is there any way to detect which control the focus is moving to in the LostFocus of the control that is losing focus?





There is no way that I am aware of to determine which field will receive the focus in form view. If you have set your tab stops in the desing view, then the focus will be in the order which you choose. If you want to know which field currently has the focus, try Conditional Formatting.If you want the focus to be specific, then you will have to code for that.

HTH

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
 
Something like this might work -

Private Sub tbxTest_LostFocus()

Dim frmCtl As control
Dim bFound As Boolean
Dim nextTab As Integer

bFound = False
nextTab = Me![tbxTest].TabIndex + 1
For Each frmCtl In Me.Controls
Select Case frmCtl.ControlType
Case acTextBox, acListBox, acCommandButton, acCheckBox[/color red]
If frmCtl.TabStop And (frmCtl.TabIndex >= nextTab) Then
MsgBox "Next control: " + frmCtl.Name
bFound = True
Exit For
End If
End Select
Next
If Not bFound Then
MsgBox "Last tab stop on form."
End If

End Sub

NOTE: you will have to add some values to the case statement (which I have marked red) if there are different types of controls on the form.

Coley
 
What if it isn't the next control in the tab order... the user clicks on the control?
 
What if it isn't the next control in the tab order... the user clicks on the next control?
 
If what you are referring to is the cursor in another field that is not in the proper tab order, have the field change colors when it has focus. In addition to the blinking cursor, the color will automatically change. If someone should click on a control button, by accident, to exit the form, then use the vbyes/no concept (On Click of the button) to allow the acceptance and store the record or to return to the current record.

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top