Strange tab results

SteveL13
SteveL13 used Ask the Experts™
on
I have a form with several tabs.  What is the best way to make the cursor jump to the first field on the next tab when leaving the last field on the current tab?  I've tried this in the onexit event of the last field on the current tab but the tab controls gets real erratic with no predictable result.  In fact, if I cursor to the FIRST field on the current tab, I get taken to the first field on the next tab as an example.


Me.pagTabName.SetFocus
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
There is no convenient way to do what you are asking for.

"In fact, if I cursor to the FIRST field on the current tab, I get taken to the first field on the next tab as an example."

Do you mean if you tab out of the last field on a tab it takes you back to the first field on that tab?  What I have found is that if you have the "Cycle" property (Other tab of the Properties dialog set to "All Records", tabbing out of the last control on the first tab will actually change to the next record and move the cursor to the control with the lowest tab index property on the current tab.

The only way I can think of to do this would be to add some code to the KeyDown event of the last control on the tab that looks something like:

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

    If KeyCode = vbKeyTab Then
        KeyCode = 0
        Me.Page12.SetFocus   '<= page12 is tab #2 in my test
        Me.Months.SetFocus  '<= Months is the controlname of the first field on the 2nd tab
    End If
    
End Sub

Open in new window

Author

Commented:
No. I want to go to the first field of the next tab.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Steve, you are talking about the tab control, on a form, right?

There is no easy way to do this.  Tab controls are meant to allow the user to work within a single tab, and manually select the next tab they want to go to.

However, the code I provided will do what you want, you just need to modify it to use the correct tab page names and control names.  You must put the code in the KeyDown event of the last control on each tab, and then change the two lines that identify the tab which you want to have the focus, and the control within that tab that you want to move to.

I strongly encourage you to make sure that your forms "Cycle" property is set to Current Record as well, to prevent you from inadvertently moving to the next record.


Dale
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I'll try it now.  By the way, I always cycle forms to Current Record.  I don't know why anyone would ever do anything different.

Author

Commented:
Thanks again as always.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
You're welcome.

Glad that worked for you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial