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

Key down event for controlling flow

Status
Not open for further replies.

yoshe

Technical User
Jan 12, 2007
36
US
Hello, I am trying to use key down (If KeyCode=vbKeyTab) to control the flow from one control to another on a form with subforms on a tab control. I initially used the LostFocus event, but this drives people crazy if they use the mouse to navigate rather than tab (they click into a field but the lost focus sends them somewhere else). So I only want to set the focus if tab is pressed. Here is the problem: the focus is always going to the next field in the tab order, and skipping the one where i want it to go. What could be the reason for this? I've tried on 3 different keyboards and same result.
 
Is this what you want?

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
    Case 38
        KeyCode = 0
        If Not Me.Recordset.BOF Then
            Me.Recordset.MovePrevious
        End If
    Case 40
        KeyCode = 0
        If Not Me.Recordset.EOF Then
            Me.Recordset.MoveNext
        End If
End Select
End Sub
 
Remou, I'm not really sure what this is supposed to do. Tab is coming up as KeyCode=9 for me. I tried substituting that in the cases, but that basically prevents the cursor from moving. Also, I want to move between recordsets, ie from the end of one subform to the beginning of the next, or some other field on the parent form.
 
How are ya yoshe . . .

Have you tried rearranging the tab order?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1, yes, it works as desired if I switch the tab order and code it to go to one control previous in the order. Kind of ugly though and throws off the flow for people who click into a field. A google search brought up this:
Not sure if it applies to me, since it does seem to capturing the tab, but i'll play around with it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top