Tab Control Event?

hi there

Registered User.
Local time
Today, 16:46
Joined
Sep 5, 2002
Messages
171
hi folks,

i have a tabbed entry form with a title label across the top of the form. the title label is not on the tab control. there are 2 tabs on my tab control. what i would like to do is have 2 title labels and have the appropriate label appear when the corresponding tab is selected. i tried writing the following code and placing it in the OnClick event on the tab, but it isn't working. does someone know what i'm doing wrong. i think maybe i'm not referencing the control properly. the tab is named "Page32". the tab control itself is named "RequirementTabControl"


Private Sub Page32_Click()
On Error GoTo Finally

If (Forms!frmRequirementEntry.RequirementTabControl = "Page32") Then
Forms!frmRequirementEntry.AssignEquipmentLabel.Visible = True
Else
Forms!frmRequirementEntry.AssignEquipmentLabel.Visible = False

Finally:
If (Err.Number <> 0) Then
MsgBox Err.Description, vbExclamation, "Error"
End If

End Sub

many thanks for any help.
 
Code:
Private Sub tabControl_Change()
    If Me.tabControl = 1 Then
        lblYourTitle.Caption = "First Page"
    Else
        Me.lblYourTitle.Caption = "Second Page"
    End If
End Sub



You could also do it like this:

Code:
Private Sub tabControl_Change()
    Me.lblYourTitle.Caption = IIf(Me.tabControl = 1, "First Page", "Second Page")
End Sub


The first is faster though, due to evaluation purposes.


If you have more tabs, in the future, it would be best to use the Select Case structure.


i.e.


Code:
Private Sub tabControl_Change()
    Select Case Me.tabControl
        Case Is = 1 
            Me.lblYourTitle.Caption = "First Page"
        Case Is = 2
            Me.lblYourTitle.Caption = "First Page" 
        Case Else
            Me.lblYourTitle.Caption = "Other Page"
    End Select
End Sub
 
awesome mile,

that worked great. i never thought about using a single label and changing the caption.

thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom