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