set focus on next tab when last field loses focus

set focus on next tab when last field loses focus

Post by mcnewsx » Thu, 18 Dec 2003 07:56:35


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

thanks,
mcnews
 
 
 

set focus on next tab when last field loses focus

Post by PC Datashe » Thu, 18 Dec 2003 08:44:33

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

 
 
 

set focus on next tab when last field loses focus

Post by mcnewsx » Thu, 18 Dec 2003 08:55:27

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
 
 
 

set focus on next tab when last field loses focus

Post by PC Datashe » Thu, 18 Dec 2003 11:00:10

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
 
 
 

set focus on next tab when last field loses focus

Post by Rick Brand » Thu, 18 Dec 2003 23:06:43


focus

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.


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com