[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 611
  • Last Modified:

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?
0
ronallard
Asked:
ronallard
  • 5
  • 2
  • 2
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now