Move to next tTab on TabCtl using VBA

I know I can programatically move to the next tab on the tabctl using:
[Tab2Name].SetFocus

My problem - My tabs are named Tab0 - Tab5. I am on Tab1, in a subform. The subform has a button called "ContinueButton". In the onclick event I would like to move to Tab2. I tried several renditions of the command the closest, "  Forms![frmProcessReports]![TabCtl0].[Tab2].SetFocus  ", but errors on object does not accept this action. Anyone know how to code that?
ronallardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianWrenCommented:
Let's say your main form is named frmMain, and your sub, "Frm Sub Form", is in a control named frmSub, and your control is TabCtl0.

Private Sub Continue_Click()

  Forms![frmMain]![frmSub].Form![TabCtl0].[Tab2].SetFocus  

End Sub

To refer to a subform, you must follow the control name, (the name of the control with the subform in it, not the name of the subform.  They are usually the same, but not always), with the property '.Form'.

Brian
0
tomk120999Commented:
Howdy from Dallas, ronallard.
Good one, Brian, I struggled with this one for a while myself.  The easiest way I have found to change tabs in a tab control is to set the .Value property of the tab control.  Let's say the tab control, tabCtrlA, is on SubForm1 of the MainForm, and we're starting from some control on the MainForm.  The code would go something like this:

'get to the subform
Me!SubForm1.SetFocus
'increment to the next tab
Me!tabCtrlA.Value = Me!TabCtrlA.Value+1

Note that this doesn't explicitly SetFocus to anything, it just sets the next tab as showing on-screen.  Also you get an error if your setting is '6' when you only have 5 tabs.  So, do your thing about controlling the action (you know).

Reading and Setting the .Value property can let you move between the tabs very efficiently.  Works for me.

Good luck as usual...
0
ronallardAuthor Commented:
I haven't tried any of these cause this looks like you think the Tab control is on the subform. The tab control is actually on the main form. Lets try it this way... frmParent contains TabCtl0 which contains Page0 - Page5. I select Page1 which has a subform control, (ChildWindow). sbfChild, loaded in 'ChildWindow', runs several queries then enables 'ContinueButton'. Still running sbfChild, how do I tell it to go to "Page3 of TabCtl0 on frmParent"?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

tomk120999Commented:
Good morning, ronallard.

Either of these will do it:
    Me!TabCtl0.Pages(3).SetFocus
    ... or ...
    Me!TabCtl0.Value = 3

If you need to qualify the statement more fully use "frmParent.TabCtrl0" instead of "Me!TabCtrl0".  That should do it.

good luck as usual...
0
tomk120999Commented:
Sorry, I forgot to mention this, but the tab control page numbers are 0-based (0, 1, 2...), so if the page 3 you mentioned is the *third* page of the control, then its number would be 2.

good luck as usual...
0
BrianWrenCommented:
You can refer to the main form of a subform this way:

Me.Parent...

So Me.Parent!TabCtl0.Value = 3
or Me.Parent!TabCtl0.Pages(3).SetFocus
etc.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomk120999Commented:
Good one, Brian, I had overlooked that!
0
ronallardAuthor Commented:
Sorry Tom - but when I tried these the only ones that worked are the ones with the Me.Pareent on them. Your syntax gave error "Microsoft Access can't find field TabCtl0 ...." Thanks for the help Brian. Both instructions worked as you had suggested.
0
tomk120999Commented:
Brian knows!  I'm currently working in Access 2000, maybe that why.  Glad you have a solution.

good luck as usual...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.