tabControl focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

tabControlReservations contains Jobfrm, which in turn contains
tabControlInvoice. When my user clicks tabControlReservations tab 2
(value=1) I want to ensure that tabControlInvoice is set to its first tab
(value=0).

I get no error, but tabControlInvoice returns to whatever tab was previously
viewed instead of 'resetting' to tab0.

Can anyone help?

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations.Pages.Count = 1 Then
Me.Jobfrm.tabControlInvoice.Page.Count = 0
End If
End Sub

Thanks.
 
Your code is wrong; don't use the .Count property. Try this:

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations.Pages = 1 Then
Me.Jobfrm.tabControlInvoice.Page = 0
End If
End Sub
 
Thanks for responding Ken. I hope you can help me. I tried your suggestion.

Without the 'count' in the If statement I get -- Argument not optional. So
I include it.

Then I get compile error: method or data member not found.

I change from 'Me.Jobfrm' to 'Me!Jobfrm' and it compiles with no effect.
 
Me.Jobfrm.tabControlInvoice = 0

redFred said:
Thanks for responding Ken. I hope you can help me. I tried your suggestion.

Without the 'count' in the If statement I get -- Argument not optional. So
I include it.

Then I get compile error: method or data member not found.

I change from 'Me.Jobfrm' to 'Me!Jobfrm' and it compiles with no effect.
 
If it's a subform, you can't use "Me" IIRC. You need to use:

Forms!Jobfrm.tabControlInvoice (and then whatever else you want to do.)
 
redFred said:
tabControlReservations contains Jobfrm, which in turn contains
tabControlInvoice. When my user clicks tabControlReservations tab 2
(value=1) I want to ensure that tabControlInvoice is set to its first tab
(value=0).

I get no error, but tabControlInvoice returns to whatever tab was previously
viewed instead of 'resetting' to tab0.

Can anyone help?

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations.Pages.Count = 1 Then
Me.Jobfrm.tabControlInvoice.Page.Count = 0
End If
End Sub


You can't set the Count property.

Just set the tab control's Value to the page index you want
selected:

If Me.tabCtrlReservations = 1 Then
Me.Jobfrm.tabControlInvoice = 0
End If
 
Sorry - should be Page:

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations.Page = 1 Then
Me.Jobfrm.tabControlInvoice.Page = 0
End If
End Sub
 
Here's what I am now trying, without getting an error, but without getting
proper results, either. It is still in tabCtrlReservations change event.

If Me.tabCtrlReservations.Pages.Count = 1 Then
Forms![frm1 Client].Reservationfrm.Jobfrm.tabControlInvoice = 0
End If

Main form (frm1 Client) has a subform (Reservation.frm).
Reservation.frm has a tab control (tabCtrlReservations) with multiple tabs.
tabCtrlReservations contains (on tab1, tab0 has subform too) a subform
(Jobfrm).
Jobfrm has a tab control (tabControlInvoice) with multiple tabs, with
subforms.

Do you see any issue?

Thanks.
 
Thanks to you all!

This is what works:
If Me.tabCtrlReservations = 1 Then
Forms![frm1
Client].Form!Reservationfrm.Form!Jobfrm.Form!tabInvoice.SetFocus
End If
 
If Me.tabCtrlReservations.Pages.Count = 1 Then
Assuming you have more than one page (and why have a tab control if you
don't? <g>), the Count will always be greater than 1, making this statement
always False, so the line following it will never execute (as you have
observed).

Don't use Count. The Value property of the Tab control returns the PageIndex
value of the currently selected Page *or sets* the currently selected page
to the one with that PageIndex value. When the Change event fires, Value
already contains the "new" PageIndex. Since Value is the Default property of
a tabControl, you don't have to explicitly write it out in code.

Therefore,

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations = 1 Then
Me.Jobfrm.tabControlInvoice = 0
' Same as
' Me.Jobfrm.tabControlInvoice.Value = 0
End If
End Sub

If you wanted to refer to the Pages by name rather than by position, you
could use this syntax:

Private Sub tabCtrlReservations_Change()
If Me.tabCtrlReservations.Pages(Me.tabCtrlReservations).Name =
"NameOf2ndPage" Then
Me.Jobfrm.tabControlInvoice =
Me.Jobfrm.tabControlInvoice.Pages("NameOf1stPage").PageIndex
End If
End Sub


Where:
1) tabCtrlReservations and tabControlInvoice are the names of
TabControls (not pages on tab controls)
*and*
2) Jobfrm is the name of the *control containing* a subform (This may or
may not be the same as the name of the subform itself, but the distinction
is important. We never really care about the names of subforms themselves,
unless we are setting the SourceObject property for a subform control).

Note that in either case, when a Page is changed via code it will cause the
Change event for the changed tab to fire (so if you changed the page of the
current tab you'd fire the same Change event a 2nd time). This usually isn't
a problem, just something to be aware of.


HTH,
 
Back
Top