set focus on next tab when last field loses focus

  • Thread starter Thread starter mcnewsxp
  • Start date Start date
M

mcnewsxp

how to force the next tab page to have focus after tabbing out of last field
on current tab?

thanks,
mcnews
 
Put the following code in the module behind your form:

Public Sub GoToNextPage()
If Me!NameOfTabControl.Value < Me!NameOfTabControl.Pages.Count - 1 Then
Me!NameOfTabControl.Value = Me!NameOfTabControl.Value + 1
Else
Me!NameOfTabControl.Value = 0
End If
End Sub

Then put the following code in the OnExit event of the last field in the tab
order on each tab:

GoToNextPage
 
i like this.
could you explain why your approach might be better than just setting focus
to first control of next tab?

thanks much,
mcnews
 
You use the same code (GoToNextPage) in the last control of each page. If you
add a new page it still is the same code. If you delete a page, the code gets
automatically deleted with the page. You can change the tab order of controls
(other than the last control) on any page and you don't have to change the code;
it still works. You can also move controls (except the last one) from one page
to another page and the code still works.

Steve
PC Datasheet
 
mcnewsxp said:
i like this.
could you explain why your approach might be better than just setting focus
to first control of next tab?

I prefer not to use the Exit or LostFocus event for stuff like this. They
work fine when the user leaves your control via the Tab or Enter key, but
if they leave that control by clicking somewhere with the mouse (or go
backwards by using Shift-Tab), then this code will override the user's
desired action and force them to go where you "thought" they were going.
This would be very irritating I should think.

The method I use is to add a small-but-visible TextBox to the TabPage and
make it last in the TabOrder. In its GotFocus event I run code to set
focus to the next TabPage. The only way this control ever gets focus and
thus the only time my code runs is if they leave the last "useful" control
on the page via the Tab or Enter key. It does not interfere with other
movements the user might make.
 
Back
Top