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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Colored Tabs

Status
Not open for further replies.

PaulF

Technical User
Jul 14, 2000
1,522
US
Although you can't change the color of the tabs when you use the Tab Control from the Toolbar, you can emulate a tab control with a few labels and rectangles. You don't get the nice rounded corners, but you are able to change colors.
I created a form that has simulated 3 tabs, 2 with labels that are used as command buttons and the 3rd to contain a subform. I use labels because you can set the backstyle to Transparent which allows the colors to show through, and still activate code with a click and if you set their Special Effect property to Raised, they resemble a command button.
This example also includes the code to change the font color of the command buttons when the mouse moves over them.

So create a form and place one large rectangle in the center to simulate the large area of the tab sheet(s). Set the following properties:
Visible: Yes
Back Style: Normal
Back Color: -2147483633
Special Effect: Raised
Name: boxFrame
Add this to the Events for the box
On Mouse Move: =fResetBold()

Add 3 smaller boxes just barely touching the top of the larger box. These will simulate the Tabs that you click on. Set the following properties:
Visible: Yes
Back Style: Normal
Back Color: 14276548
Special Effect: Raised
Name: box1 (and box2, and box3)
Border Color: 14276548
Add these to the Events for the boxes
for box1
On Click: =fSetTab("lbl1")
for box2
On Click: =fSetTab("lbl2")
for box3
On Click: =fSetTab("lbl3")

Add a label over each of these 3 smaller boxes to hold the captions that you want on each tab. Set the following properties:
Visible: Yes
Back Style: Transparent
Border Style: Transparent
Caption: Tab #1 (and Tab #2, and Tab #3)
Name: lbl1 (and lbl2, and lbl3)

Add these to the Events for the labels
for lbl1
On Click: =fSetTab("lbl1")
for lbl2
On Click: =fSetTab("lbl2")
for lbl3
On Click: =fSetTab("lbl3")

add 5 labels to be used as command buttons an place them evenly spaced inside the large box (increase the size of boxFrame if necessary) and wide enough to hold the captions we will set in code. Set the following properties:
Caption: (add a blank space)
Visible: No
Back Stype: Transparent
Border Style: Transparent
Special Effect: Raised
Name: cmd1 (and cmd2, cmd3, cmd4, cmd5)

Add these to the Events for the labels being used as command buttons

for cmd1
On Click: =fDoEvents("1")
On Mouse Move: =fSetBold("cmd1")
for cmd2
On Click: =fDoEvents("2")
On Mouse Move: =fSetBold("cmd2")
for cmd3
On Click: =fDoEvents("3")
On Mouse Move: =fSetBold("cmd3")
for cmd4
On Click: =fDoEvents("4")
On Mouse Move: =fSetBold("cmd4")
for cmd5
On Click: =fDoEvents("5")
On Mouse Move: =fSetBold("cmd5")

create a form based on any table, and make sure it is small enough to be used as a subform. Place a subform control inside the large box (over the command button labels)that uses your small form, and set the following properties:
Visible: No
Special Effect: Raised
Name: Sub1
Tab Stop: No

create one final textbox (remove the associated label). This is to capture the focus when leaving the subform and is not required if the tabs only contain labels.
set the following properties:
Visible: Yes
Height: 0
Width: 0
Name: txtFocus
Tab Stop: No

For the Detail Section Set the following:
Back Color: 14276548
Add this to the Detail's Events
On Mouse Move: = fResetBold()

Add this to the code window behind the form

'======================================
'Start of Code
Dim strCtl As String
Dim blnset As Boolean
Dim strTab As String

Function fDoEvents(strIn As String)
Select Case strIn
Case "1"
Select Case strTab
Case "1"
Call s11
Case "2"
Call s21
End Select
Case "2"
Select Case strTab
Case "1"
Call s12
Case "2"
Call s22
End Select
Case "3"
Select Case strTab
Case "1"
Call s13
Case "2"
Call s23
End Select
Case "4"
Select Case strTab
Case "1"
Call s14
Case "2"
Call s24
End Select
Case "5"
Select Case strTab
Case "1"
Call s15
Case "2"
Call s25
End Select
End Select
End Function

Function fResetBold()
If blnset = True Then
If strCtl <> "" Then
Me(strCtl).ForeColor = 0
Me(strCtl).FontBold = False
End If
blnset = False
End If
End Function
Function fSetBold(sI As String)
If blnset = False Then
If strCtl <> "" And strCtl <> Null Then
Me(strCtl).ForeColor = 0
Me(strCtl).FontBold = False
End If
If sI = "cmd5" And strTab = "1" Then
Me(sI).ForeColor = vbRed
Else
Me(sI).ForeColor = vbBlue
End If
Me(sI).FontBold = True
strCtl = sI
blnset = True
End If
End Function

Private Function fSetButtons(strIn As String)
Select Case strIn
Case "1"
cmd1.Caption = vbCrLf & "Tab 1 Command Button 1"
cmd1.Visible = True
cmd2.Caption = vbCrLf & "Tab 1 Command Button 2"
cmd2.Visible = True
cmd3.Caption = vbCrLf & "Tab 1 Command Button 3"
cmd3.Visible = True
cmd4.Caption = vbCrLf & "Tab 1 Command Button 4"
cmd4.Visible = True
cmd5.Caption = vbCrLf & "Close Form"
cmd5.Visible = True
txtFocus.SetFocus
Me.Sub1.Visible = False
Case "2"
cmd1.Caption = vbCrLf & "Tab 2 Command Button 1"
cmd1.Visible = True
cmd2.Caption = vbCrLf & "Tab 2 Command Button 2"
cmd2.Visible = True
cmd3.Caption = vbCrLf & "Tab 2 Command Button 3"
cmd3.Visible = True
cmd4.Caption = vbCrLf & "Tab 2 Command Button 4"
cmd4.Visible = True
cmd5.Caption = vbCrLf & ""
cmd5.Visible = False
txtFocus.SetFocus
Me.Sub1.Visible = False
Case "3"
cmd1.Caption = vbCrLf & ""
cmd1.Visible = False
cmd2.Caption = vbCrLf & ""
cmd2.Visible = False
cmd3.Caption = vbCrLf & ""
cmd3.Visible = False
cmd4.Caption = vbCrLf & ""
cmd4.Visible = False
cmd5.Caption = vbCrLf & ""
cmd5.Visible = False
Me.Sub1.Visible = True
End Select
strTab = strIn
End Function

Function fSetTab(sTab As String)
Dim ctl As Control
Select Case sTab
Case "lbl1"
box1.BackColor = 14677945
box2.BackColor = 14276548
box3.BackColor = 14276548
boxFrame.BackColor = 14677945
Call fSetButtons(1)
strTab = "1"
Case "lbl2"
box1.BackColor = 14276548
box2.BackColor = 12302320
box3.BackColor = 14276548
boxFrame.BackColor = 12302320
Call fSetButtons(2)
strTab = "2"
Case "lbl3"
box1.BackColor = 14276548
box2.BackColor = 14276548
box3.BackColor = 15914739
boxFrame.BackColor = 15914739
Call fSetButtons(3)
strTab = "3"
End Select
End Function

Private Sub Form_Open(Cancel As Integer)
Call fSetTab("lbl1")
End Sub

Private Sub s11()
MsgBox "Tab 1 Command Button 1 Was Clicked"
End Sub

Private Sub s12()
MsgBox "Tab 1 Command Button 2 Was Clicked"
End Sub

Private Sub s13()
MsgBox "Tab 1 Command Button 3 Was Clicked"
End Sub

Private Sub s14()
MsgBox "Tab 1 Command Button 4 Was Clicked"
End Sub

Private Sub s15()
DoCmd.Close acForm, Me.Name
End Sub

Private Sub s21()
MsgBox "Tab 2 Command Button 1 Was Clicked"
End Sub

Private Sub s22()
MsgBox "Tab 2 Command Button 2 Was Clicked"
End Sub

Private Sub s23()
MsgBox "Tab 2 Command Button 3 Was Clicked"
End Sub

Private Sub s24()
MsgBox "Tab 2 Command Button 4 Was Clicked"
End Sub

Private Sub s25()
'This Command Button Not Used
End Sub

'End of Code
'=============================================================

Save the form and test it. It shows that you can get around some bland controls if you want to add a little code.
PaulF
 
I went there before I did this... I decided to approach it differently

PaulF
 
This thread thread702-474863 basically does the same thing. However, I've modified it since to look like this (can't find that thread though)

Here's how I made it work. First, set the OnClick event of each label to =SelectTab("NameOfTheLabel",valueOfLabel) where "valueOfLabel" represents the value of the Tab the label represents.

Then, insert this code into the code view of the module. This code keeps track of which label is currently selected (height raised) via the variable mstrLabelSelected. It also basis the top property on the FormHeader rather than the tab control. But, you can do it either way. This should help to get you started. Also, the reason I multiply by 1440 is to convert the units to twips.

Option Compare Database
Option Explicit

Dim mstrLabelSelected As String

Public Function SelectTab(strLabelSelected As String, intValue as Integer)

If (strLabelSelected <> mstrLabelSelected) Then

Me(mstrLabelSelected).Height = 0.2083 * 1440
Me(mstrLabelSelected).Top = (FormHeader.Height - (0.2083 * 1440))

Me(strLabelSelected).Top = (FormHeader.Height - (0.25 * 1440))
Me(strLabelSelected).Height = 0.25 * 1440

tabCtl.Value = intValue

mstrLabelSelected = strLabelSelected

End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top