[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change the Color of a Command Button with VBA Code

Posted on 2014-04-24
13
Medium Priority
?
2,412 Views
Last Modified: 2014-04-28
I have a Combo Box [cboReportCateg] and when a user chooses an option from this combo box, I want a command button [cmdAssocReport] on that same form to change colors (preferably RED).

Also, is there anywhere that provides the codes for all the different colors?

How can I do this with VBA Code?

Thanks,

gdunn59
0
Comment
Question by:gdunn59
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40021440
what version of access are you using?

if you are using version < access 2010
you can use labels instead of command button
labels has click events too.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40021459
I'm using Access 2010.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1200 total points
ID: 40021480
try


me.cmdAssocReport.backcolor=rgb(255,0,0)

see this sample db
Database001.accdb
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 1

Author Comment

by:gdunn59
ID: 40022870
Rey Obrero:

I tried what you suggested, but nothing happened.

Here is the code that I have (I am using it on the AfterUpdate of another field):

cboReportCateg_AfterUpdate

If Me.cboReportCateg = "Associate" Then
    Me.cmdAssocRpt.Enabled = True
    
    Me.cmdAssocRpt.BackColor = RGB(255, 0, 0)

Open in new window



What am I doing wrong?

Thanks,
gdunn59
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40023179
did you download the sample db ?
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40023230
I'm not able to download the database because of HIPAA laws.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1200 total points
ID: 40023447
did you apply Themes when you created your form?
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40024032
No I didn't apply themes.

Another strange thing.  Since I tried the code to change the color of the command button, now everytime I open that form my SetFocus command is giving me a 2105 run-time error wherein it wasn't doing that before.

Really strange.  I've checked everything and can't figure out why it started doing this.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40024046
Rey,

Ok.  Ignore my last posting ID: 40024032, for some reason it had put a record source in the Form.  I removed that, and the error went away.

But I'm still having the issue with the command button color not changing by using your code referenced:

me.cmdAssocReport.backcolor=rgb(255,0,0)

I noticed that your code is on the OnClick, mine is on the AfterUpdate of a combo box, and it reference's a command button on the same form, which is the command button that I want to change colors.

Thanks,
gdunn59
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40024064
<No I didn't apply themes>

you should apply themes to enable the command buttons to change its color.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40026709
Rey, how do you apply themes?

Thanks,

gdunn59
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40027005
in the design view of the form, select the command button then hit F4
in the Format tab, look for the "Use Theme" property and set it to YES
0
 
LVL 1

Author Comment

by:gdunn59
ID: 40027467
Hi Rey,

Thanks.  I figured it out.

Here is what I ended up doing (I actually ended up changing the color to GREEN).

I used the following code on the AfterUpdate of the cboReportCateg Combo Box (this is just part of the code.  I also used the same block of code for the other combo boxes I have in the OnEnter):

If Me.cboReportCateg = "Associate" Then
    Me.cmdAssocRpt.Enabled = True
    Me.cmdAssocRpt.UseTheme = True
    Me.cmdAssocRpt.BackColor = RGB(0, 255, 0)

Open in new window


I also, put the following code in the OnEnter of the cboReportCateg Combo Box):

Private Sub cboReportCateg_Enter()
    
    Me.cboCategSelect.RowSource = ""
    
    Me.cboReportCateg.Dropdown
    
    Me.cmdAssocRpt.Enabled = False
    Me.cmdProcessAvg_Emp.Enabled = False
    Me.cmdDeptReportSummary.Enabled = False
    Me.cmdEmpScorecardRptByDate.Enabled = False
    Me.cmdDetErrRpt.Enabled = False
    Me.cmdMgrErrorDetailRpt.Enabled = False
    Me.cmdMgrRpt.Enabled = False
    Me.cmdNumofAudits.Enabled = False
    Me.cmdTop10.Enabled = False
    
    
    Me.cmdAssocRpt.UseTheme = False
    Me.cmdProcessAvg_Emp.UseTheme = False
    Me.cmdDeptReportSummary.UseTheme = False
    Me.cmdEmpScorecardRptByDate.UseTheme = False
    Me.cmdDetErrRpt.UseTheme = False
    Me.cmdMgrErrorDetailRpt.UseTheme = False
    Me.cmdMgrRpt.UseTheme = False
    Me.cmdNumofAudits.UseTheme = False
    Me.cmdTop10.UseTheme = False
    
End Sub

Open in new window

Thanks for your assistance.  Works exactly like I want it to.

gdunn59
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question