Can a command buttons background color be changed?

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!!
 
D

Douglas J. Steele

If txtComments1 <> "" Then
Me.MoreComments1.BackColor = vbRed
Else
Me.MoreComments1.BackColor = vbGreen
End If
 
M

Marshall Barton

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
 
S

sweet_dreams

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.
 
D

Dirk Goldgar

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.
 
D

Douglas J. Steele

Sorry, you're correct. While the subject line mentions "command buttons", I
didn't notice that when reading the post.
 
D

Douglas J. Steele

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top