Lock Tab Control until selection is made?

You can reference your tabs with either a string name or an index value. The public variable will be the intLastTab variable and it seems to me that you unhide the tabs with the string name of the tab so the variable should be a string so I would change the name of the variable to strLastTab.
 
OK,
I've changed it to this
Code:
Private Sub Form_Current()
Me.tab_more_info .Pages(strLastTab).Visible = False
strLastTab = Me.tab_more_info
End Sub

and then I added the other piece of code
Code:
Private Sub cmdTabs_Click()
Dim x As Integer

On Error GoTo Err_cmdTabs_Click

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

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

Exit_cmdTabs_Click:
    Exit Sub

Err_cmdTabs_Click:
    MsgBox Err.Description
    Resume Exit_cmdTabs_Click
    
End Sub

what is 'cmdTabs' is that the name of the tabs? or something else?

I'm also still getting that error message too. any idea what would cause that?
 
Sorry! cmdTabs was the name of a CommandButton on *my* test form that I used to verify the code to walk through the index of the tab control. How many tabs will be visible at any one time? While you are responding to this question I'm going to go back and review the code you've posted so far so we can come up with the exact code necessary to achieve the results you want.
 
Ah OK, I was wondering that cmd button was for :)

There will be about 13 tabs, they might want more or less later, but I'm sure I could figure out how to tweak the code once it's working..

Thank You again for your help with this!
 
I am using this tab control process your thinking about
and also some of the fields are visible /invisible as well


a lot of coding is involved - but the end result is worth it

g
 
Sorry! cmdTabs was the name of a CommandButton on *my* test form that I used to verify the code to walk through the index of the tab control. How many tabs will be visible at any one time? While you are responding to this question I'm going to go back and review the code you've posted so far so we can come up with the exact code necessary to achieve the results you want.

Looks like I'm only going to have a total of 6 tabs, and only 1 tab would be shown at a time depending on the selection made.
 
That makes it easier. Let's use the string name of each tab for the operation making the public variable strLastTab. The code to set the visibility will be:
Me.YourTabCtrl.Pages(strLastTab).Visible = False '-- hide that vale visible tab
strLastTab = "TabPage2" '-- or whatever is the name of the tab.
Me.YourTabCtrl.Pages(strLastTab).Visible = True '-- Make the next tab visible.
 
Now I have to ask: how many different ways/controls will be controlling which tab is visible? Will it always be through one particular ComboBox?
 
yes, it's one combobox, that has 6 options, each option goes along with one of the tabs on the tab control.

This will be the only way to access the tab control.
 
Great! What is the RowSourceType and RowSource of the ComboBox?
 
Row Source Type is Table/Query
and Row Source is SELECT q_active_edits.Edit_Type, q_active_edits.Edit_Type_ID FROM q_active_edits ORDER BY [Edit_Type];
 
I am going to assume that the q_active_edits.Edit_Type field is a text field and the data is the same as the names of each tab and that the bound column is 1. That would make the AfterUpdate event of the ComboBox something like:
Code:
Private Sub YourCBOName_AfterUpdate()

   Me.YourTabCtrl.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
   strLastTab = Me.YourCBOName                      '-- Save the Next visible tab name
   Me.YourTabCtrl.Pages(strLastTab).Visible = True  '-- Make the next tab visible.

End Sub
...using your real control names of course. We should also have some error handling code in the event. Will all of the tabs be invisible until the user makes a selection in the ComboBox?
 
I am going to assume that the q_active_edits.Edit_Type field is a text field and the data is the same as the names of each tab and that the bound column is 1. That would make the AfterUpdate event of the ComboBox something like:
Code:
Private Sub YourCBOName_AfterUpdate()

   Me.YourTabCtrl.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
   strLastTab = Me.YourCBOName                      '-- Save the Next visible tab name
   Me.YourTabCtrl.Pages(strLastTab).Visible = True  '-- Make the next tab visible.

End Sub
...using your real control names of course. We should also have some error handling code in the event. Will all of the tabs be invisible until the user makes a selection in the ComboBox?

cool!
Yes all the tabs would be invisible until the selection is made.

Yes it is also a text field that is bound to column 1
 
When you've got it coded then post your code inside code tags so we can see it. We'll need to test for an empty public variable as well as add error handling.
 
When I set the public variable, did you want me to subsitute my_ctrl_tab with the name of my tab control?

Dim tab_more_info As String

Code:
Option Compare Database
Option Explicit
Dim tab_more_info As String


Private Sub cbo_edit_type_AfterUpdate()

   Me.IIR.Pages(strLastTab).Visible = False '-- hide the Previous visible tab
   strLastTab = Me.cbo_edit_type                      '-- Save the Next visible tab name
   Me.Gender.Pages(strLastTab).Visible = True  '-- Make the next tab visible.

End Sub
 
I just named it tab_more_info

wasn't too sure what the naming convention was for tab controls, i've never used them before.
 
You are going to want something that looks more like:
Code:
Option Compare Database
Option Explicit
Dim strLastTab As String

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
 
You are going to want something that looks more like:
Code:
Option Compare Database
Option Explicit
Dim strLastTab As String

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

OK I've added this, but it doesn't seem to be doing anything. All the tabs are visible when the form opens. Do I need to set the visible property back to no?

If I make a selection from the dropdown I get the following message.
run time error 2467
The expression you entered referrs to a object that doesn't exist.
 
Back in Post #6 of this thread I gave you the code to make all of the tab pages invisible. You need to put that code in the OnLoad event of your form. The error you are reporting makes me suspect that we are not using the correct name for the TabControl.
 

Users who are viewing this thread

Back
Top Bottom