View Full Version : Tabbing out of subform


aimeepeter
05-28-2008, 08:49 AM
Hi all,
I have written this code:

Private Sub TestStaff_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
[Forms]![Shows Form]![Model#].SetFocus
End If
End Sub

to move from the end of a sub form to the next control on the main form. However when this is run, the focus is set to the 2nd next control on the form - it jumps over the next control [Model#] - weird.

Is there another way to write this code to move from the last field on the subform to the next field in sequence on the main form. Perhaps code to jump to a specific number in the tab order??

Cheers!

georgedwilkinson
05-28-2008, 09:43 AM
Why aren't you using the Tab Order property?

RuralGuy
05-28-2008, 09:43 AM
Since you still have a Tab key pending, guess what happens after you set the focus to the [Forms]![Shows Form]![Model#] control. ;) Just go ahead and eat the Tab key with:
If KeyCode = 9 Then
[Forms]![Shows Form]![Model#].SetFocus
KeyCode = 0
End If

aimeepeter
05-28-2008, 10:00 AM
Thanks RuralGuy - that did the trick!

In repsonse to the post from georgedwilkinson can you please explain how to use the tab order property to go from the subfrom back to the main form? I know how to set the tab order to move from the main to sub form and then to use Ctrl-Tab to move back to the main form, but how do you use the Tab Order Property to move back to the main form without the user needin to Ctrl-Tab.

Cheers!

RuralGuy
05-28-2008, 10:03 AM
Glad I could help.

georgedwilkinson
05-28-2008, 10:36 AM
I didn't understand that was what you were doing. The only way I've ever been able is by using datasheet view in my subform. It doesn't work with continuous.

I like Allan's response much better.

aimeepeter
05-28-2008, 10:57 AM
Case closed.
Thank you both!