Lock Tab Control until selection is made?

You're talking about this piece of code here right
Code:
Private Sub cmdTabs_Click()
Dim x As Integer

On Error GoTo Err_cmdTabs_Click

For x = 0 To Me.TabCtl0.Pages.Count - 1

  Me.TabCtl0.Pages(x).Visible = Not Me.TabCtl0.Pages(x).Visible
  
Next x

Exit_cmdTabs_Click:
    Exit Sub

Err_cmdTabs_Click:
    MsgBox Err.Description
    Resume Exit_cmdTabs_Click
    
End Sub

I was never really sure on which event to put it?
You had it on click of a button, I tried putting it on load of the form, and I get a 'cannot hide a control that has focus' warning when the form is opened.
 
Here is the code after I edited it.
my combobox is named cbo_edit_type
and the tab control is named
tab_more_info

Does it matter what the pages within the tab control are named? I would think so, but not sure how they relate to each other in the code?

Code:
Private Sub cbo_edit_type_AfterUpdate()

   If Len(strLastTab & "") > 0 Then
      Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
   End If
   strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
   Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.

End Sub
 
I was never really sure on which event to put it?
You had it on click of a button, I tried putting it on load of the form, and I get a 'cannot hide a control that has focus' warning when the form is opened.
I would think the cbo_edit_type ComboBox would have the focus when the form opens rather than the TabControl. Go to View>Tab Order... and move the ComboBox to the top of the list and then try opening the form.
 
That's what I thought too, and went in and made sure the tab control wasn't first on the list. I also moved the combo box to the top of the list, but it didn't make any difference.

What I just noticed tho, it is hiding the first page of my tab ctrl. It's not hiding the rest tho, and the second page in the tab control consits of a cbo box, where they can select a gender.
 
I just tried removing that page, and it made no difference tho.
It still hides the first page of the ctr, but I get that message and none of the rest hide.
 
In design mode can you go to each page and set the visible property to NO and save the form. That should start the form with all of the tab pages invisible. Comment out the OnLoad event code for now.
 
OK,
Got it working!!!

I forgot you said I would need to name the pages the same as the bound column (#1).
Did that and it's working now.

The only thing I need to fix now is, there are some options within the dropdown that don't need to open a tab. Currently if I do that, I get that 'object referenced' error.

So is there a way to make it so, if one of these options are selected. It just ignores the 'open tab' code?
 
If I understand the question correctly then you can put a Select Case structure in the AfterUpdate event so you can be selective in what you do.
Code:
Private Sub cbo_edit_type_AfterUpdate()

Select Case Me.cbo_edit_type

   Case "A good Value"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
   Case "A Bad Value"
      'Do Nothing
   Case Else
      'Do Nothing
End Select

End Sub
 
Yes,
There may be 10 options from the dropdown menu, but only maybe 6 require additional information to be filled out via the tab control.

I added the code above, but now it doesn't seem to do anything when any of the items are selected. All the tabs stay invisible

I should just subsitute the above from what I had before right?
 
Am I heading in the right direction with this

Code:
Private Sub cbo_edit_type_AfterUpdate()

Select Case Me.cbo_edit_type

Case "1"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
Case "2"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
   Case "A Bad Value"
      'Do Nothing
   Case Else
      'Do Nothing
End Select

End Sub

Just add a new case for each option that needs one.

This appears to work, the only thing I can think of. Is if they accidently select the wrong option, it opens a tab when they really wanted an option that had no tab. If they re-select the right option, the tab is still visible.

So I should be able to modify this
Code:
If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If

To make it invisible right?
 
You are correct!
Code:
Case "A Value NOT needing a tab"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = ""                      '-- Reset the variable to reflect no Tab open
 
That's Perfect!
Thank You again for your help with this, this works great!!
 
One of my better forms I think. :p:D Just kidding. :o Glad I could help.
 
One last question (I hope!)

Could I use this or something similar on a report?
I tried converting my form to a report, but the tab control is just blank.

Is it possible to control a tab control in the same fashion inside a report?
 
Is it possible to control a tab control in the same fashion inside a report?
The answer is NO because controls are not Interactive within a report. It is only for printing so you can't select a control, like you can on a form, like you can on a report.
 
oops sorry, didn't explain myself well.

What I meant was too have only the appropriate tab display depending on what was selected in the combo field.

So when the report is run,
If field a is set to XX

Only the XX tab would appear in the report.
 
I've never attempted to put a tab control on a report but you could certainly design a report that was different depending on what tab was selected.
 
Right now, it only the first tab will appear if it matches what's in the edit_type field. I can't seem to get any of the other tabs to appear when there is anything else in the edit type box.

Should something like this work?


Private Sub Report_Open(Cancel As Integer)
If Me.Edit_Type = "IIR" Then
Me.IIR.Pages.Visible = True
End If
If Me.Edit_Type = "CCE" Then
Me.CCE.Pages.Visible = True
End If
End Sub
 
As I said, I've never tried to put a tab control on a report so I have no idea how it would react. I can see that you should revisit the code we already have on how to reference a TabControl page.
 
Sorry to bump an old thread of mine, but I noticed something today that I didn't notice before.

My tabs seem to be working good for the most part, but for this.

I'm using a version of this tab on 2 different forms, but it's doing the same thign on both.

On the main entry form, when the form opens the tabs are invisible (that's good!)
If they select an entry that require additional info, the correct tab opens (even better!)
But if they select an option by mistake, and then select the correct one that doesn't need additonal info, the tab that opened on their first selection remains visible (not so good)

I never noticed this before, so not sure if it's always done this or not? Here is my code, does that look right?

Code:
 Select Case Me.cbo_edit_type

Case "1"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
Case "2"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
Case "3"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
      
Case "5"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
      
Case "7"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
      
Case "8"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.


Case "9"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
      Me.tab_more_info.Pages(strLastTab).Visible = True  '-- Make the next tab visible.
      

      
Case "4"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = ""                      '-- Reset the variable to reflect no Tab open
      
Case "6"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = ""                      '-- Reset the variable to reflect no Tab open
   
Case "A Value NOT needing a tab"
      If Len(strLastTab & "") > 0 Then
         Me.tab_more_info.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
      End If
      strLastTab = ""                      '-- Reset the variable to reflect no Tab open
   
   Case Else
      'Do Nothing
End Select
End Sub
 

Users who are viewing this thread

Back
Top Bottom