Setfocus is going to the wrong place

  • CanuckBuck

    Hall of Fame

    Points: 3890

    I have a control on a subform with the following code

    Private Sub Project_Name_DB_Key_Cbo_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 9 Then 'It's a Tabkey

    If Shift = 1 Then ' It's a ShiftTab. Move backward in the tab order of the main from


    Else ' It's a forward tab. Move to the next control in the tab order of the main from


    End If

    End If

    End Sub

    on a Tab keypress (the else) condition, focus quickly moves to Regulatory_Sector_DB_Key and then on to the next control in the tab order. A similar thing happens on a ShiftTab keypress - focus goes to Application_Cbo and then on to the previous control in the tab order.

    I've tried variations of the naming convention for the control e.g.

    - Me.Parent.

    - Me.Parent!

    all have the same behavior.

    If anyone has any ideas about how to prevent this unwanted behavior I'd appreciate a pointer.

    Thanks in advance.

  • CanuckBuck

    Hall of Fame

    Points: 3890

    I've also tried the DoCmd.GoToControl ("Regulatory_Sector_DB_Key")

    The behavior is the same... 🙁

  • WendellB

    SSCrazy Eights

    Points: 8627

    I think you need to use the Forms!FormName.ControlName syntax or the Me.Parent.ControlName syntax to get the desired behavior. Tab key behavior when you are using subforms and want to get back to the main form is always a tricky thing.

    Colorful Colorado
    You can't see the view if you don't climb the mountain!

  • CanuckBuck

    Hall of Fame

    Points: 3890

    I'm so glad to finally have some knowledge to contribute back to the forum!

    The answer to this problem is that the key press, in this case a tab key (or back tab) is being passed on to the control which receives focus, resulting in the tab being executed on the . So, my solution is simply to change the KeyCode to some other value (not exactly sure what it should be yet - I used 0, but I'm not sure if that's the right code to use).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply