Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SSTab1.Tab in code 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,502
US
I have a Form1, and placed SSTab1 on it (with default 3 Tabs)
on very first Tab (Tab 0) I placed Label1

I have this very simple code:

Code:
Option Explicit

Private Sub Form_Load()
SSTab1.Tab = 1
SSTab1.Tab = 0
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
If SSTab1.Tab = 0 Then
    Label1.BackColor = vbRed
End If
End Sub

What I want is: no matter which Tab is selected at design time, I want to go thru SSTab1_Click event on Form_Load. Why? There are certain settings I have in SSTab1_Click event and I want first Tab (tab 0) to be always selected when Form starts.

The interesting part here is:
If during design time I select second tab (Tab 1) (or any other tab but Tab 0) and run my code, SSTab1.Tab = 0 in Form_Load 'kicks in' and Tab 0 is selected and my label is red. Great.

But...
If during design time I select first tab (Tab 0) and run my code, code in Form_Load is 'ignored' and my label is black, not red. :-(

So I have to bery careful to save my Form with Tab1 or 2 selected in order for my Form to work the way I want.

What's going on?


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Why don't you just call the click event yourself instead of relying on the event?


Code:
Private Sub Form_Load()

SSTab1.Tab = 0
Call SSTab1_Click(0)

End Sub


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Works great. Thank you George :)


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Or put the code currently contained in SSTab1_Click into a Private Sub and call that Sub from Form_Load and SSTab1_Click.
Some frown on calling event procedures directly although I confess I am a serial offender...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top