Tab Button Color Change

J

Jeff C

Built a tabbed form and changed the tabs to buttons....pulled the following
code off another Access Web Site. It is intended to be assigned to the "on
click event" and changes the font on the button to red when clicked. I have
assigned code to other events for other things by pasting in but this is
above me and I cannot find the correct location to put this. I am also
haveing difficulty figuring out what to replace the "cmdYourCommand" with.
Anyone out there have the patience to direct me?

Private Sub cmdDetails_Click()
Me.pag1.SetFocus
Me.cmdYourCommand.ForeColor = 255
Me.cmdYourCommand.ForeColor= 16711680
Me.cmdYourCommand.ForeColor = 16711680
End Sub
'Where cmdYourCommand is the name of the other pages you wish to view, that
were once Tabs' (Hope that makes sense!!).

Thank You..it is by doing that I learn
 
D

Dirk Goldgar

Jeff C said:
Built a tabbed form and changed the tabs to buttons....pulled the
following code off another Access Web Site. It is intended to be
assigned to the "on click event" and changes the font on the button
to red when clicked. I have assigned code to other events for other
things by pasting in but this is above me and I cannot find the
correct location to put this. I am also haveing difficulty figuring
out what to replace the "cmdYourCommand" with. Anyone out there have
the patience to direct me?

Private Sub cmdDetails_Click()
Me.pag1.SetFocus
Me.cmdYourCommand.ForeColor = 255
Me.cmdYourCommand.ForeColor= 16711680
Me.cmdYourCommand.ForeColor = 16711680
End Sub
'Where cmdYourCommand is the name of the other pages you wish to
view, that were once Tabs' (Hope that makes sense!!).

Thank You..it is by doing that I learn

Is the code supposed to change the caption color to red for the button
that was just clicked; that is, the button named "cmdDetails"? If so,
then maybe the button's Click code should be

Private Sub cmdDetails_Click()
Me.pag1.SetFocus
Me.cmdDetails.ForeColor = 255
End Sub
 
J

Jeff C

The example was demonstrated by two screen captures which showed that just
the font of the button name changed to red when clicked. I have 5 buttons..I
have pasted the code into the "on click" properties of the tbctl through the
code builder but have no luck. I preferred to ask you folks rather than
joining another site today.

maybe I should be filling in me.cmdmytabname.Forecolor =

what do you think?
 
D

Dirk Goldgar

Jeff C said:
The example was demonstrated by two screen captures which showed that
just the font of the button name changed to red when clicked. I have
5 buttons..I have pasted the code into the "on click" properties of
the tbctl through the code builder but have no luck. I preferred to
ask you folks rather than joining another site today.

maybe I should be filling in me.cmdmytabname.Forecolor =

what do you think?

The Click event of a tab control doesn't fire when you change pages.
It's not actually good for much. To detect when the tab control changes
to a new page, use the tab control's Change event. The Value of the tab
control tells you the page index of the page that is now current.

I think you are trying to set the colors of various buttons depending on
what page of the tab control is current. For that, you might use code
along these lines:

'----- start of example code -----
Private Sub tabMyTab_Change()

' Reset the caption colors of all "page" buttons, before
' changing the current button to red.

Me.cmdPage1.ForeColor = 16711680
Me.cmdPage2.ForeColor = 16711680
Me.cmdPage3.ForeColor = 16711680
Me.cmdPage4.ForeColor = 16711680

' Now set the color of the current page's button to red.
Select Case Me.tabMyTab
Case 0 : Me.cmdPage1.ForeColor = 255
Case 1 : Me.cmdPage2.ForeColor = 255
Case 2 : Me.cmdPage3.ForeColor = 255
Case 3 : Me.cmdPage4.ForeColor = 255
End Select

End Sub
'----- end of example code -----

Now the only code you need in your buttons' Click events is to change
the value of the tab control to change to the desired page:

'----- more example code -----
Private Sub cmdPage1_Click()
Me.tabMyTab = 0
End Sub

Private Sub cmdPage2_Click()
Me.tabMyTab = 1
End Sub

Private Sub cmdPage3_Click()
Me.tabMyTab = 2
End Sub

Private Sub cmdPage4_Click()
Me.tabMyTab = 3
End Sub
'----- end more example code -----
 
Top