Subform navigation

G

Gitche Gumee

I am using the On Exit event for a control on a subform to set focus back to
the next control on the main form. This works fine if the user has pressed
Tab to navigate to the next field. However, if the user uses the mouse to
click to a different field, the On Exit code will be a major annoyance.

How can I capture whether the user has pressed the Tab key to go to the next
field?
 
L

Linq Adams via AccessMonster.com

Use the KeyDown event for the subform control to trap the <Tab> key, like
this:

Private Sub SubFormControlName_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9
MainFormControlName.SetFocus
End If
End Sub
 
G

Gitche Gumee

I have found that it works -- or doesn't wor, rather -- the same with or
without the KeyPreview property on. When I tab out of the subform, it skips
over the "set focus" field and jumps to the next. ?
 
B

Bob Larson

My response was to Linq's use of the KeyDown event. If you don't have the
Key Preview set to Yes then it won't recognize the KeyDown event.

Bob Larson
 
G

Gitche Gumee

As I mentioned to Bob, this is not quite working.

Here's my code:

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

If KeyCode = 9 Then
Forms!frmMain![frm Project Information].Form![Benefit Type].SetFocus
End If

End Sub

What happens is that instead of going to [Benefit Type] (tab index 32) the
focus goes to the next field in the tab index [Opportunity type] (tab index
33).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top