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!

Button Painter 7

Status
Not open for further replies.

cariobulog

Technical User
Oct 30, 2005
44
LY
Anyone could help me how i can make my command button background color changing everytime i click it.
 
Don't use a button - use a textbox instead.
Buttons don't have a backcolor property.

Alternatively use a transparent button and place it on top of a coloured label.
 
You can use Microsoft forms command buttons
TOOLS | INSERT | MICROSOFT FORMS 2.0 COMMAND BUTTON
and use this code
Code:
Private Sub CommandButton0_Click()
    If Me.CommandButton0.BackColor = vbRed Then
        Me.CommandButton0.BackColor = vbGreen
    Else
        If Me.CommandButton0.BackColor = vbGreen Then
            Me.CommandButton0.BackColor = vbBlue
        Else
            Me.CommandButton0.BackColor = vbRed
        End If
    End If
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
thanks, but how i can change the color everytime i click
 
How many colors you need?
You can add more colors in the same way or using a select statement with color numbers too
Code:
Private Sub cmdbtn_Click()
    Select Case Me.cmdbtn.BackColor
    Case Is = vbRed
        Me.cmdbtn.BackColor = vbGreen
    Case Is = vbGreen
        Me.cmdbtn.BackColor = vbBlue
    Case Is = vbBlue
        Me.cmdbtn.BackColor = 450
    Case Is = 450
        Me.cmdbtn.BackColor = 0
    Case Else
        Me.cmdbtn.BackColor = vbRed
    End Select
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
i tried already the code is working only in fore color, but how if i want to assign color everytime i click for back color
 
My code is for backcolor not forecolor
(Microsoft Forms command button)
Access' own command button doesn't support backcolor.

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
I don't understand what you are asking..
There is a mistake in my earlier post.. I was working on HTML program.. so the insert line I said is incorrect
TOOLS | INSERT | MICROSOFT FORMS 2.0 COMMAND BUTTON
The correct menu is
INSERT | ACTIVEX CONTROL | MICROSOFT FORMS 2.0 COMMAND BUTTON

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
again, i want to assign for each click/color to open a particular subform.

thanks for your help
 
Add
[tt]Me.SubFormSpaceName.SourceObject = "SubformName"[/tt]
where ever required
Remember to change the SubFormSpaceName , SubformName to actual name.

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
sorry for the ignorance, how i can add in this code?

CODE
Private Sub CommandButton0_Click()
If Me.CommandButton0.BackColor = vbRed Then
Me.CommandButton0.BackColor = vbGreen
Else
If Me.CommandButton0.BackColor = vbGreen Then
Me.CommandButton0.BackColor = vbBlue
Else
Me.CommandButton0.BackColor = vbRed
End If
End If
End Sub
 
You won't get all the Events from the property box. Go to the code window and choose button name from the leftside combo and it's evnts from rightside combo. Events will be added to the code window automatically. You can then add lines between them.



________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
what procedure, i would take from the right combo?
 
When you choose Click form the right combo then it will add some code to the code window look like
Code:
Private Sub CommandButton0_Click()

End Sub
In between the lines you need to add
Code:
    If Me.CommandButton0.BackColor = vbRed Then
        Me.CommandButton0.BackColor = vbGreen
    Else
        If Me.CommandButton0.BackColor = vbGreen Then
            Me.CommandButton0.BackColor = vbBlue
        Else
            Me.CommandButton0.BackColor = vbRed
        End If
    End If
Hope this will help you.

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
Thanks it helps me now its working, how about if i used it in the command button of the Switchboard if may be possible. Or how i can make a swictchboard using this button.

thanks for your help.

 
Create a normal Access Command button through the wizard to open a form or report then copy the code behind it to a notepad. Delete the command button and insert a MS Forms command button, name it to the old one that was deleted. Paste the copied code to code window. Try how it is working.

________________________________________________________
Zameer Abdulla
Help to find Missing people
My father was a realistic father; not a vending machine dispense everything I demanded for!!
 
its working but it will work also if i replace the code in the default switchboard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top