Tab control question

  • Thread starter Thread starter Tony Williams
  • Start date Start date
T

Tony Williams

I have a form which has a tab control with three pages. There is also a
control on the form called txtnbrparties which can have a value of 1,2 or 3.
When the form loads I want only page 1 to be visible, if txtnbrparties is 2
I want page 1 and 2 to be visible and if the value is 3 I want all pages to
be visible.
Could someone help me with the code which I presumably need to put in the
tabcontrol page visible control?
Thanks
Tony
 
Tony said:
I have a form which has a tab control with three pages. There is also
a control on the form called txtnbrparties which can have a value of
1,2 or 3. When the form loads I want only page 1 to be visible, if
txtnbrparties is 2 I want page 1 and 2 to be visible and if the value
is 3 I want all pages to be visible.
Could someone help me with the code which I presumably need to put in
the tabcontrol page visible control?
Thanks
Tony


Set the visible property to false for the second and third pages. Then use
code...

Select Case Me!txtnbrparties
Case 1
Me!TabPage2Name.Visible = False
Me!TabPage3Name.Visible = False
Case 2
Me!TabPage2Name.Visible = True
Me!TabPage3Name.Visible = False
Case 3
Me!TabPage2Name.Visible = True
Me!TabPage3Name.Visible = True
End Select

You need to execute that code in the AfterUpdate event of the txtnbrparties
control as well as in the Current event of the Form (assuming that this is a
bound control).
 
Private Sub Form_Open(Cancel As Integer)

'You could do this at design time.
'Shown here for completeness.
Me.pgeOne.Visible = True
Me.pgeTwo.Visible = False
Me.pgeThree.Visible = False
Me.txtTest.Value = "1"

End Sub

Private Sub txtTest_AfterUpdate()

Me.pgeTwo.Visible = ((Me.txtTest.Value = "2") Or _
(Me.txtTest.Value = "3"))
Me.pgeThree.Visible = (Me.txtTest.Value = "3")

End Sub
 
Thanks I used Rick's code (sorry Brendan) and it worked just fine
Thanks again
Tony
 
Brendan,

I do not have pages. I have a main form with two subforms. I have a command
button that runs a function that I want to moveto one of the forms during
that function.
 
Either my code or Rick's will work with any control that has a Visible
property. As far as I can remember, I think that includes all of the
built-in Access form controls. It certainly includes the subform control.

Rick's post includes an important point that I forgot to mention, though -
you may need to add the code to the Current event of the form as well as the
Click event of your command button..
 

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

Back
Top