Lock Tab Control until selection is made?

cdoyle

Registered User.
Local time
Today, 15:22
Joined
Jun 9, 2004
Messages
383
In another thread someone suggested I use a tab control for a project I'm working on.

What I need overall is, a method for the user to fill in some fields that are related to a selection they made in a dropdown box.

A tab control sounds good, but is there a way to lock the tabs so the user can't select the tabs themselves?

So basically, they would make a selection in a dropdown box, and then once the do. The appropriate tab would appear, and they could enter the info for that tab?
 
Each tab has a visible property if that helps.
 
I did not see that before, that does help!

So I should be able to make the tab 'visible' by inserting some code into the afterupdate event of the dropdown right?

am I close with something like this.

If Me.cboBox1 = "Gender" Then
Me.tab_1.Visible = True
 
cool, that worked!

One other question,
As I have it now, if you make a selection the tab opens.
But if the users accidently chooses the wrong item in the drop down, and then goes back and selects the right one. The new tab opens, but the old one from before stays open too.

What would the code be to make all other tabs visible=false?

Also, I'm also going to put this tab control on another form too, this form allow the user to modify the record, but not the combo box, or it's related fields.

I thought I could put the same code on the 'before update' event, but that's not working. I put it on the 'on enter' and it would appear if the user clicks on the combo.

What event would I put the code on to make it look at the combo box, and then make the data that was already entered visible?
 
Last edited:
One other question,
As I have it now, if you make a selection the tab opens.
But if the users accidently chooses the wrong item in the drop down, and then goes back and selects the right one. The new tab opens, but the old one from before stays open too.

What would the code be to make all other tabs visible=false?
I personally would use a form public variable to feep track of the Tab that was visible and address each tab directly with:
Code:
Me.TabCtlName.Pages(intLastTab).Visible = False
intLastTab = Me.TabCtlName
...using your TabCtlName of course. Here's code to hide all of the tabs:
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
...which should give you some ideas on how to handle your tab control. Post back if I was not clear enough.
 
Also, I'm also going to put this tab control on another form too, this form allow the user to modify the record, but not the combo box, or it's related fields.

I thought I could put the same code on the 'before update' event, but that's not working. I put it on the 'on enter' and it would appear if the user clicks on the combo.

What event would I put the code on to make it look at the combo box, and then make the data that was already entered visible?
If I understand correctly then I believe you want the Current Event of the form.
 
I personally would use a form public variable to feep track of the Tab that was visible and address each tab directly with:
Code:
Me.TabCtlName.Pages(intLastTab).Visible = False
intLastTab = Me.TabCtlName
...using your TabCtlName of course. Here's code to hide all of the tabs:
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
...which should give you some ideas on how to handle your tab control. Post back if I was not clear enough.

Thanks,
I'm a little confused where to put this code tho. Do I put I still put it on the after event of the dropdown box? I don't see in this code, how the selection from the dropdown, effects the tabctrl? Or does this code work with the code I had before?
 
Not completely understanding your form I would say yes, everything could be handled in the AfterUpdate event of your ComboBox. Again, you will have to determine what tabs need to be visible and which ones should be invisible.
 
I think I need a little help putting this all together.

So would I still use the in the afterupdate event?
If Me.cboBox1 = "Gender" Then
Me.tab_1.Visible = True
To control which tabs are displayed?
Or scrap that code all together?


Then the other code you listed above, that would prevent more then 1 tab from being displayed correct? Where would it go?
I see you have cmdTabs_Click() Would this be a command button?
Should I change that to somethign else?

Just not understanding how it works, so I'm a little confused.

Thanks again for your help.
 
Putting everything in the AfterUpdate event of the combobox should be just fine. Have you come up with a method to record which tabs should be visible yet? How many tabs are we talking about?
 
There are about 13 tabs at the moment.

I originally had a popup form for each selection in the dropdown box, but thought the tabs would be cleaner. Not sure now.

To make them visible, the code I used at first seem to work, just not sure how effcient that is.
 
just not sure how effcient that is.
Just remember - to make things efficient for the user and EASY for the user, sometimes it takes a lot of work on the development side. So, alot of work for you now may save your users a lot of work later.
 
Just remember - to make things efficient for the user and EASY for the user, sometimes it takes a lot of work on the development side. So, alot of work for you now may save your users a lot of work later.

ya I've been thinking about this more and more, and the tab control is nice, but I think it would be better if there wasn't so many 'tabs' because it causes my form to be huge!

I think I might go back to the popup form instead, unless someone has a better solutions?

Thanks
 
ya I've been thinking about this more and more, and the tab control is nice, but I think it would be better if there wasn't so many 'tabs' because it causes my form to be huge!

I think I might go back to the popup form instead, unless someone has a better solutions?

Thanks
You can keep it from being so huge by setting the tab control's MULTI-ROW setting to YES.
 
OK, I did the multi-row, and that helped keep the width of the tab control down.

So now I'm back to trying to understand how to use the code that ruralguy posted.
Do I still set the visible property of each tab to no?

I can get it so each tab opens with a selection option from the dropdown, but I can't seem to make it so, it closes that tab, if a different option is selected.
 
Did you create a public variable that you set to the tab you will make visible?
 
I'm still learning VBA, and trying to look up public variables.

Would I do something like this in my form.
Public Class my_ctrl_tab
 
At the top of the code module for your form put:
Code:
Option Compare Database
Option Explicit
Dim my_ctrl_tab As String
This variable is now defined outside of any code routine and can be referenced by any routine within your form code. It is basically a public variable but only to code in this particular form.
 
OK I added
Dim tab_more_info As String

To my form (I already had the other 2 lines)

Not sure if it should do this or not, but I get a compile error.

Compile error
Member already exists in an object module from which this object derives...

not sure why it's doing that??

Now I would put this in my onCurrent event?
Code:
Me.tab_more_info .Pages(intLastTab).Visible = False
intLastTab = Me.tab_more_info
 

Users who are viewing this thread

Back
Top Bottom