Switching between 2 sets of Tab Controls...!?

D

DavidK

I have a Tab Control that I want to load secondary forms (which have their
own Tab Controls). I'm close, but still having difficulty correctly setting
focus on the secondary forms.

frmDASHBOARD has TabCtl0 with 7 tabs/pages (0-6)
onChange page(1) I load frmAUTO which has TabCtl1 also (coincidentally) with
7 tabs/pages (0-6)
onChange page(2) I load frmCONSOLIDATION which has TabCtl2 with 7 tabs/pages
(0-6)
onChange page(3) I load frmFLOORPICK which has TabCtl3 with... etc, etc.
onChange page(4)...
onChange page(5)...
onChange page(6)...

The onChange event on frmMAIN correctly identifies the secondary form to
load but I cannot get the focus set on the secondary forms. I can get the
onChange event on the secondary forms to set focus on any page I want on
frmMAIN (even though it should always return to page(0)). But my VB code
doesn't seem to recognize TabCtl1 - TabCtl6

Here is my main form onChange code:

Private Sub TabCtl0_Change()
' When click on one of the Dept tabs, open Dept form on 2nd tab
If Me.TabCtl0.Value = 1 Then
DoCmd.OpenForm "AUTO"
TabCtl1.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 2 Then
DoCmd.OpenForm "CONSOLIDATION"
TabCtl2.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 3 Then
DoCmd.OpenForm "FLOOR PICK"
TabCtl3.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 4 Then
DoCmd.OpenForm "MANUAL"
TabCtl4.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 5 Then
DoCmd.OpenForm "PALLET MOD"
TabCtl5.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 6 Then
DoCmd.OpenForm "SHIPPING"
TabCtl6.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 7 Then
DoCmd.OpenForm "IRG"
TabCtl7.Pages(1).SetFocus
End If
End Sub

On the return, my code works fine:

Private Sub TabCtl1_Change()
' When click on Home tab, open DASHBOARD form on 1st tab
If Me.TabCtl1.Value = 0 Then
DoCmd.OpenForm "DASHBOARD"
TabCtl0.Pages(0).SetFocus
End If
End Sub

Any help would be appreciated - I'm going nuts with this!
 
D

Dirk Goldgar

DavidK said:
I have a Tab Control that I want to load secondary forms (which have their
own Tab Controls). I'm close, but still having difficulty correctly
setting
focus on the secondary forms.

frmDASHBOARD has TabCtl0 with 7 tabs/pages (0-6)
onChange page(1) I load frmAUTO which has TabCtl1 also (coincidentally)
with
7 tabs/pages (0-6)
onChange page(2) I load frmCONSOLIDATION which has TabCtl2 with 7
tabs/pages
(0-6)
onChange page(3) I load frmFLOORPICK which has TabCtl3 with... etc, etc.
onChange page(4)...
onChange page(5)...
onChange page(6)...

The onChange event on frmMAIN correctly identifies the secondary form to
load but I cannot get the focus set on the secondary forms. I can get the
onChange event on the secondary forms to set focus on any page I want on
frmMAIN (even though it should always return to page(0)). But my VB code
doesn't seem to recognize TabCtl1 - TabCtl6

Here is my main form onChange code:

Private Sub TabCtl0_Change()
' When click on one of the Dept tabs, open Dept form on 2nd tab
If Me.TabCtl0.Value = 1 Then
DoCmd.OpenForm "AUTO"
TabCtl1.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 2 Then
DoCmd.OpenForm "CONSOLIDATION"
TabCtl2.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 3 Then
DoCmd.OpenForm "FLOOR PICK"
TabCtl3.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 4 Then
DoCmd.OpenForm "MANUAL"
TabCtl4.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 5 Then
DoCmd.OpenForm "PALLET MOD"
TabCtl5.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 6 Then
DoCmd.OpenForm "SHIPPING"
TabCtl6.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 7 Then
DoCmd.OpenForm "IRG"
TabCtl7.Pages(1).SetFocus
End If
End Sub

On the return, my code works fine:

Private Sub TabCtl1_Change()
' When click on Home tab, open DASHBOARD form on 1st tab
If Me.TabCtl1.Value = 0 Then
DoCmd.OpenForm "DASHBOARD"
TabCtl0.Pages(0).SetFocus
End If
End Sub

Any help would be appreciated - I'm going nuts with this!


At the very least, you need to qualify your references to controls on other
forms with a reference to the form in question. So try this, for example:

'----- start of suggested code -----
Private Sub TabCtl0_Change()

Dim strFormToOpen As String

' When click on one of the Dept tabs, open Dept form on 2nd tab

Select Case Me.TabCtl0.Value
Case 1
DoCmd.OpenForm "AUTO"
Forms!AUTO!TabCtl1.Pages(1).SetFocus
Case 2
DoCmd.OpenForm "CONSOLIDATION"
Forms!CONSOLIDATION!TabCtl2.Pages(1).SetFocus
Case 3
DoCmd.OpenForm "FLOOR PICK"
Forms![FLOOR PICK]!TabCtl3.Pages(1).SetFocus
Case 4
DoCmd.OpenForm "MANUAL"
Forms!MANUAL!TabCtl4.Pages(1).SetFocus
Case 5
DoCmd.OpenForm "PALLET MOD"
Forms![PALLET MOD]!TabCtl5.Pages(1).SetFocus\
Case 6
DoCmd.OpenForm "SHIPPING"
Forms!SHIPPING!TabCtl6.Pages(1).SetFocus
Case 7
DoCmd.OpenForm "IRG"
Forms!IRG!TabCtl7.Pages(1).SetFocus
End Select

End Sub
'----- end of suggested code -----

You'll note that I changed your If ... ElseIf ...ElseIf ... structure to
Select Case, which is neater and more efficient for testing a single
expression for each of a list of values.

I'm not sure this is entirely correct, though, because you said your tab
control had 7 pages, in which case -- as you quite rightly said -- those
pages would be numbered 0 to 6. But your code was testing your tab control
for values of 1 to 7. But you said it was working, so I have to assume that
you really have at least 8 tab pages. I left the code with the same page
numbers you were using. If, on the other hand, you were mistaken, just
change the Case values from 1-7 to 0-6.

Incidentally, I don't see how this code:
DoCmd.OpenForm "DASHBOARD"
TabCtl0.Pages(0).SetFocus

.... can be completely working, because TabCtl0 needs to be qualified with a
form reference:

Forms!DASHBOARD!TabCtl0.Pages(0).SetFocus

I'm mystified as to how your original code could have avoided giving you an
error message at run time.
 
D

DavidK

Dirk -

Thank you very much for your prompt reply. And your explanation was concise
and clear (thank you). You have helped me to better understand the Select
Case structure. I have converted my code as you suggested and fully
qualified my referrences.

I built my db at work with Access 2003, and right now at home I'm testing it
with Access 2007 and getting no response to the code at all (my original or
your revision). How (in)compatible are 2003 db's with 2007 - especially
regarding Tab Controls and VB?

DavidK


--
DWK-


Dirk Goldgar said:
DavidK said:
I have a Tab Control that I want to load secondary forms (which have their
own Tab Controls). I'm close, but still having difficulty correctly
setting
focus on the secondary forms.

frmDASHBOARD has TabCtl0 with 7 tabs/pages (0-6)
onChange page(1) I load frmAUTO which has TabCtl1 also (coincidentally)
with
7 tabs/pages (0-6)
onChange page(2) I load frmCONSOLIDATION which has TabCtl2 with 7
tabs/pages
(0-6)
onChange page(3) I load frmFLOORPICK which has TabCtl3 with... etc, etc.
onChange page(4)...
onChange page(5)...
onChange page(6)...

The onChange event on frmMAIN correctly identifies the secondary form to
load but I cannot get the focus set on the secondary forms. I can get the
onChange event on the secondary forms to set focus on any page I want on
frmMAIN (even though it should always return to page(0)). But my VB code
doesn't seem to recognize TabCtl1 - TabCtl6

Here is my main form onChange code:

Private Sub TabCtl0_Change()
' When click on one of the Dept tabs, open Dept form on 2nd tab
If Me.TabCtl0.Value = 1 Then
DoCmd.OpenForm "AUTO"
TabCtl1.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 2 Then
DoCmd.OpenForm "CONSOLIDATION"
TabCtl2.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 3 Then
DoCmd.OpenForm "FLOOR PICK"
TabCtl3.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 4 Then
DoCmd.OpenForm "MANUAL"
TabCtl4.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 5 Then
DoCmd.OpenForm "PALLET MOD"
TabCtl5.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 6 Then
DoCmd.OpenForm "SHIPPING"
TabCtl6.Pages(1).SetFocus
ElseIf Me.TabCtl0.Value = 7 Then
DoCmd.OpenForm "IRG"
TabCtl7.Pages(1).SetFocus
End If
End Sub

On the return, my code works fine:

Private Sub TabCtl1_Change()
' When click on Home tab, open DASHBOARD form on 1st tab
If Me.TabCtl1.Value = 0 Then
DoCmd.OpenForm "DASHBOARD"
TabCtl0.Pages(0).SetFocus
End If
End Sub

Any help would be appreciated - I'm going nuts with this!


At the very least, you need to qualify your references to controls on other
forms with a reference to the form in question. So try this, for example:

'----- start of suggested code -----
Private Sub TabCtl0_Change()

Dim strFormToOpen As String

' When click on one of the Dept tabs, open Dept form on 2nd tab

Select Case Me.TabCtl0.Value
Case 1
DoCmd.OpenForm "AUTO"
Forms!AUTO!TabCtl1.Pages(1).SetFocus
Case 2
DoCmd.OpenForm "CONSOLIDATION"
Forms!CONSOLIDATION!TabCtl2.Pages(1).SetFocus
Case 3
DoCmd.OpenForm "FLOOR PICK"
Forms![FLOOR PICK]!TabCtl3.Pages(1).SetFocus
Case 4
DoCmd.OpenForm "MANUAL"
Forms!MANUAL!TabCtl4.Pages(1).SetFocus
Case 5
DoCmd.OpenForm "PALLET MOD"
Forms![PALLET MOD]!TabCtl5.Pages(1).SetFocus\
Case 6
DoCmd.OpenForm "SHIPPING"
Forms!SHIPPING!TabCtl6.Pages(1).SetFocus
Case 7
DoCmd.OpenForm "IRG"
Forms!IRG!TabCtl7.Pages(1).SetFocus
End Select

End Sub
'----- end of suggested code -----

You'll note that I changed your If ... ElseIf ...ElseIf ... structure to
Select Case, which is neater and more efficient for testing a single
expression for each of a list of values.

I'm not sure this is entirely correct, though, because you said your tab
control had 7 pages, in which case -- as you quite rightly said -- those
pages would be numbered 0 to 6. But your code was testing your tab control
for values of 1 to 7. But you said it was working, so I have to assume that
you really have at least 8 tab pages. I left the code with the same page
numbers you were using. If, on the other hand, you were mistaken, just
change the Case values from 1-7 to 0-6.

Incidentally, I don't see how this code:
DoCmd.OpenForm "DASHBOARD"
TabCtl0.Pages(0).SetFocus

.... can be completely working, because TabCtl0 needs to be qualified with a
form reference:

Forms!DASHBOARD!TabCtl0.Pages(0).SetFocus

I'm mystified as to how your original code could have avoided giving you an
error message at run time.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

DavidK said:
Dirk -

Thank you very much for your prompt reply.

You're welcome.
I built my db at work with Access 2003, and right now at home I'm testing
it
with Access 2007 and getting no response to the code at all (my original
or
your revision). How (in)compatible are 2003 db's with 2007 - especially
regarding Tab Controls and VB?

There's little or nothing that is incompatible, but 2007 has a different
security model. You need to put your database in a trusted location, as
designated in the Trust Center settings, which you can get to from the
"Office Button". I can't recall offhand, but I think you may need to go to
the Access Options from the Office button, and from there to the Trust
Center.

Most people designate their Documents folder and all its subfolders as
trusted locations, so if you put your database there the code should not be
disabled.
 
D

DavidK

Wooooo Hoooooooooooooo!

You have solved my Tab Control problem! I have wrestled with that aligator
off-and-on for weeks.

You made it soooo easy. Of course, its always easy - when you know how! I
imagine brain surgery is probably easy - if you know how! And in my case -
YOU KNEW HOW!

Thank you very much. As you can tell I'm new to Access. I put together a
good application design document and my employer has me started on a project
weeks before training is being made available - so I've been reading and
experimenting for a month. Much of my content is working, but navigation was
stuck in the mud without those tabs working right.

If I get real stuck in the mud again, I know where to turn for help.
 
D

Dirk Goldgar

DavidK said:
Thank you very much.

You're very welcome.
As you can tell I'm new to Access. I put together a
good application design document and my employer has me started on a
project
weeks before training is being made available - so I've been reading and
experimenting for a month.

It looks to me like you've been going about your self-training the right
way.
If I get real stuck in the mud again, I know where to turn for help.

These newsgroups are one of the best resources out there. And don't forget
that Google Groups can help you search old newsgroup postings going back a
loooong way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top