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

Button colour on form 8

Status
Not open for further replies.

slames

Technical User
Nov 5, 2002
211
GB
How can I change the colur of a button on a form?, can't find that property anywhere...
Thanks
Steph
 
You can't. what you can do is create an object on the form and give it the appearance of being a button, then place your code in the OnClick event of the object. You can change theback colour of your object to anything you fancy.

 
I hate to say it, but this particular piece of functionality is simply not available in Access.


An alternative which I've found quite versatile is to use a label or a picture as a button. Then you can make it any colour you like, use any graphics you like and in any style you like. The only drawback is you've got to put in the VBA behind the label yourself, rather than using the wizard.

Hope this helps,



Dodgy Chris
-----------------------------------

confucious say : better to save a mans life than to build 7 storey pagoda
 
Sorry Krispi, I wasn't trying to repeat what you'd said, I think we posted at about the same time...

[noevil]

Dodgy Chris
-----------------------------------

confucious say : better to save a mans life than to build 7 storey pagoda
 
You can also create the colored label, place it directly under the button, and set the button transparent property to yes.....

this way you CAN use the wizard, and just build a label or picture or whatever under it. The button is still activated, but you only see the object.

****************************
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
I had never thought of that! Superb idea!!! A star for you...

[shocked]



Dodgy Chris
-----------------------------------

confucious say : better to save a mans life than to build 7 storey pagoda
 
Mstrmage1768, I am not sure if you keep notifications on your old threads, so if you do, thank you. Your button colour advice was perfect. Pink Star to you. JL
 
slames, try this thread

thread702-571169

Regards

Paul
 
mstrmage1768, because of your suggestion above, I got rid of my switchboard and did it all by forms. I was "coloring" my buttons and had some problems. Someone else answered my problem thread and said to use hyperlink's instead. That worked even better. However, there were some buttons that I could not use the hyperlink on and would still like to colorize them. Here is the problem: I have a command button called "RETURN" and a label called "UNDER". I place the label where I want it. I put the command button on top of the label. However, when I then click on the button, nothing happens. If I move the label, the command button works. I have this problem in several different forms and places. Since you suggested this method, I was hoping you could tell me what I am doing wrong? Thanks, Janet Lyn
 
select the command button and in the menu bar at the top of access, click Format -> Bring To Front. You are stacking the objects as suggested, but the label is still "layered" above the command button.....by bringing the command button to the front, you are putting it into the top layer....

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
When you have a label under the button. You click on it and yes it works with the code.But Does anyone know to to see the actual click. Like for example you click a button it goes down and up. Anyone???
 
You could do similar using a transparent background label (containing the caption) overlaying an image (containing no text). On our in-house system I animate the image by setting the PictureData property, so that the label Mouse Move event copies the image from an invisible 'Active' picture and resets all other buttons to a copy of the 'Inactive' picture.

The form has several (in this case 12) images called Butt1 to Butt12, overlaid by labels called lblOption1 to lblOption12. It also has 3 invisible images called ButtonActive, ButtonInactive and ButtonPressed that have the relevant pictures set. The CurrentPic array elements are set as: 0 - inactive, 1 - active, 2 - pressed.

Apologies for the great swathes of code (only code for first 'button' included) - it does look good though ...

Code:
Const MaxButtons = 12
Dim CurrentPic(MaxButtons) As Long
Dim CurrentButton As Long
Dim AnimateButtons As Boolean

Private Sub ButtonClick(ButtNo As Long)
On Error GoTo ErrBClick:
DoCmd.Hourglass True
DoCmd.Echo False, "Opening Form ..."
Select Case ButtNo
Case 1:
    DoCmd.OpenForm "Gen Client"
'etc ...
Case Else
    Beep
End Select
DoCmd.Hourglass True

ExitBClick:
On Error Resume Next
lblWait1.Visible = False
lblWait2.Visible = False
DoCmd.Echo True
DoEvents
DoCmd.Hourglass False
Exit Sub

ErrBClick:
DoCmd.Echo True
MsgBox Err.DESCRIPTION
Resume ExitBClick:
End Sub

Private Sub SetButtonActive(ButtNo As Long)
Dim A As Long
If AnimateButtons Then
    For A = 1 To MaxButtons
        If A = ButtNo Then
            If CurrentPic(A) <> 1 Then
                Me.Controls(&quot;Butt&quot; & CStr(A)).PictureData = ButtonActive.PictureData
                CurrentPic(A) = 1
                CurrentButton = ButtNo
            End If
        Else
            If CurrentPic(A) <> 0 Then
                Me.Controls(&quot;Butt&quot; & CStr(A)).PictureData = ButtonInactive.PictureData
                CurrentPic(A) = 0
            End If
        End If
    Next A
End If
End Sub

Private Sub SetButtonPressed(ButtNo As Long)
Dim A As Long
If AnimateButtons Then
    For A = 1 To MaxButtons
        If A = ButtNo Then
            If CurrentPic(A) <> 2 Then
                Me.Controls(&quot;Butt&quot; & CStr(A)).PictureData = ButtonPressed.PictureData
                CurrentPic(A) = 2
                CurrentButton = ButtNo
            End If
        Else
            If CurrentPic(A) <> 0 Then
                Me.Controls(&quot;Butt&quot; & CStr(A)).PictureData = ButtonInactive.PictureData
                CurrentPic(A) = 0
            End If
        End If
    Next A
End If
End Sub

Private Sub SetAllButtonsInactive()
Dim A As Long
If AnimateButtons Then
    For A = 1 To MaxButtons
        If CurrentPic(A) <> 0 Then
            Me.Controls(&quot;Butt&quot; & CStr(A)).PictureData = ButtonInactive.PictureData
            CurrentPic(A) = 0
        End If
    Next A
    CurrentButton = 0
End If
End Sub

Private Sub Butt1_Click()
ButtonClick 1
End Sub

Private Sub Butt1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetButtonPressed 1
End Sub

Private Sub Butt1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button And 1) = 1 Then
    SetButtonPressed 1
ElseIf Button = 0 Then
    SetButtonActive 1
End If
End Sub

Private Sub Butt1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetButtonActive 1
End Sub

Private Sub Form_Load()
Dim A As Long
AnimateButtons = Not IsTerminalServer() 'Declaration not included
For A = 0 To MaxButtons
    CurrentPic(A) = 0
Next A
CurrentButton = 0
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetAllButtonsInactive
End Sub

Private Sub lblOption1_Click()
Butt1_Click
End Sub

Private Sub lblOption1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Butt1_MouseDown Button, Shift, X, Y
End Sub

Private Sub lblOption1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Butt1_MouseMove Button, Shift, X, Y
End Sub

Private Sub lblOption1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Butt1_MouseUp Button, Shift, X, Y
End Sub
 
i think there's no easy way since your button is Invisible but you could &quot;draw&quot; another label that look like a Pressed Button and place it under the button with the other label and toggle visible/invisile if the Button is pressed

jul ^_^
 
sure.....you simply use the code of the command button to make the label sink and unsink......

Make sure you set the SpecialEffect Property of the Label to Raised (or 1 in VBA code)

Next in the OnClick event of your command button, you are running some code......now you encapsulate this with your label manipulation...

Private Sub Command1_OnCLick

Me![Label].SpecialEffect = 2 ' This makes it sink

' You code here

Me![Label].SpecialEffect = 1 ' This raises it again

End Sub

Good luck and happy hunting.

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Man guys (or gals)I guess I hit the hot topic. Thanks Judge for answering so Mstrmage for answering so quickly. Thanks everyone else for all the ideas. I'll get this stupid database finished yet. Stars for everyone. Janet Lyn
 
mstrmage1768 ,by far a better solution than mine! good thing I didn't do it :)

jul ^_^
 
The unfortunate thing about changing the SpecialEffect property in the Click event is that, since the event happens when the command button is released, the label &quot;button&quot; goes down a little late. It just looks a little off, especially if the user lingers on the mouse button before releasing it.

Additional things you can do to make this look and work even more like a command button:

You can make the visual effect work exactly like a command button by setting SpecialEffect to 2 in the command button's MouseDown event, and to 1 in the MouseUp event, instead of in the Click event. (Of course, you'd still perform the code associated with the button's function in the Click event.)

You can also create the down/up visual effect when the command button has the focus and the user presses the Space bar. In the command button's KeyDown and KeyUp events, test whether the key pressed was a space (KeyCode=32), and if so, set SpecialEffect to 2 or 1, respectively. (mstrmage1768's method already works for the keyboard, because the Click event can be driven by either the mouse or keyboard selection of the command button.)

To take it even a step further, you can simulate the dotted rectangle around the caption when the command button has the focus. Remove the caption from the button label. Create another label, smaller than the button label, and put the caption on it. Set its BackStyle and BorderStyle to Transparent and its BorderColor to black. Resize it to make it as small as possible without cutting off the caption. Center it over the label button, then select the real command button, and select Format|Bring To Top from the menu. In the command button's GotFocus event, change the little label's BorderStyle to Dots (4), and in the LostFocus event change the little label's BorderStyle back to Transparent (0).

To make the simulation complete, you can even add a keyboard accelerator to this &quot;button&quot;. (A keyboard accelerator is the underlined letter you put in a caption so that you can use Alt+<letter> on the keyboard to select the control.) Just add the &quot;&&quot; character to the little label's caption before your accelerator character, then copy and paste the little label's Caption to the real command button's Caption (it won't display because the button is transparent). When you press Alt+<letter> on the keyboard, it's the real command button that will be selected, even though it's invisible.

With these additions, the button will look and work almost exactly like a CommandButton. The only differences I know of are: (1) the dots in the dotted border style are larger and farther apart than the dots in the focus indicator of a real command button control, and (2) the caption and focus rectangle don't shift (those of a real command button move down and to the right one pixel while the button is depressed).

All this attention to nuances! Am I anal or what?

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
And that is why Rick is one of the greatest!!! Thanks. Star for you!

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Awwrrr, shucks! Thank you!

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Rick, I will give it a try and see what happens. Thanks so much. I had just come back to this thread to let Mstrmage know his code worked but I did not see anything, and found your thread answering the why to that question. Janet Lyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top