Can a command buttons background color be changed?

  • Thread starter Thread starter GD
  • Start date Start date
G

GD

I'm wondering if it can be changed by any means, but especially through code
as in:

If txtComments1 <> "" Then
cmd.MoreComments1 {is red}
Else
cmd.MoreComments1 {is green}

If the background color can't be changed in this way, can the font color?
That would be my second choice.

Thanks for your time!!
 
If txtComments1 <> "" Then
Me.MoreComments1.BackColor = vbRed
Else
Me.MoreComments1.BackColor = vbGreen
End If
 
GD said:
I'm wondering if it can be changed by any means, but especially through code
as in:

If txtComments1 <> "" Then
cmd.MoreComments1 {is red}
Else
cmd.MoreComments1 {is green}

If the background color can't be changed in this way, can the font color?
That would be my second choice.


Buttons do not have a BackColor property, but they do have
the ForeColor property.

If txtComments1 <> "" Then
Me.MoreComments1.ForeColor = vbRed
Else
Me.MoreComments1.ForeColor = vbGreen
End If
 
As far as I'm concenred button doesn't have BackColor property. But
You can make button transparent and put under it label and change
labels BackColor - it will imitate buttons property.
 
GD said:
I'm wondering if it can be changed by any means, but especially through
code
as in:

If txtComments1 <> "" Then
cmd.MoreComments1 {is red}
Else
cmd.MoreComments1 {is green}

If the background color can't be changed in this way, can the font color?
That would be my second choice.


A command button has no BackColor property. You can change the ForeColor,
and I've done that upon occasion.

If you're willing to expend the effort, you can assign the button a picture,
which has the caption text with the background color you like, and swap
pictures to make it seem like the BackColor is changing. I believe Stephen
Lebans has bundled up this functionality in the sample database posted here:

http://www.lebans.com/cmdbutton.htm
CommandButton.zip is a database containing functions to
allow a user defined BackColor and Rotated Text for
Command Buttons.
 
Sorry, you're correct. While the subject line mentions "command buttons", I
didn't notice that when reading the post.
 
To refer to a control on an arbitrary form, use
Forms![NameOfForm]![NameOfControl], so in your case you'd use
Forms!frmMoreComments!txtComments7

However, note that the others are correct: there's no BackColor property for
command buttons.
 
Back
Top