Getting a comman button to change colors with the Tab button highlighted (1 Viewer)

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
when I hover over a command button with the mouse I can set the properties of that button to change color. But what I need now it to have that same thing happen when I use the tab button to highlight that button. I cant seem to find a way to do that. I have tried to change the color with the on got focus, but that only seemed to work after I pressed the button any thoughts
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,644
What was your code? I just briefly tested and the ForeColor changed as directed as I tabbed through the button.
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
well i tried this only after having the on got focus didnt work ' Me.cmdSaveRecord.BackColor = RGB(255, 0, 0) How did you make yours work? I also was wondering if I have some other programming stopping the process I will go try it in another database
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,644
In a test db:

Code:
Private Sub Command6_GotFocus()
  Me.Command6.ForeColor = vbRed
End Sub

Private Sub Command6_LostFocus()
  Me.Command6.ForeColor = vbYellow
End Sub
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
Ok I tried it in another database and used this code Me.cmdSaveRecord.BackColor = &HEFF2F7 in the ON GOT FOCUS and it worked like a charm.
I wonder why it would not work in the database I am working in hmmmm
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,644
Not sure. Back color may depend on other settings of the button.
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
I am beginning to think it has something to do with the buttons that are on the form. I will delete the button and start over.
 

The_Doc_Man

Happy Retired Curmudgeon
Joined
Feb 28, 2001
Messages
15,548
1. Since this is an introduction forum, welcome seeker9969.

2. Normally we prefer that you don't ask techie questions in the intro section. Your question would have been more appropriate under "Forms."

HOWEVER, that is not a dig because (a) you're new and we will cut you some serious slack and (b) with the turmoil caused by Jon having to change to a new forum base software ('cause the old one was out of date and not supported any more), none of us know where anything is, and (c) once it gets figured out, some moderator will probably move the thread for you anyway. So call that an FYI, not a poke.

3. I have never had trouble using "GotFocus" to change the color of a control. However, as you tried it on another database and it worked, that is a sign of possible corruption in the first DB. I can't point to such an article right now, but look up the Access "/DECOMPILE" command line option. Do that, then go in and compile your code. See if that fixes the miscreant DB.
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
OH yes the compile thing I forgot about that. that totally makes sense. I will go try it I did go remove the button and was able to get it working. Of course one my worst nemesis is what I dont know about programming is not helpiong me much LOL thanks for all the help :)
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
how to i get this color so I can use it in VBA #26BC34 here is the code i used Me.cmdOpenForm.BackColor = #26BC34
 

The_Doc_Man

Happy Retired Curmudgeon
Joined
Feb 28, 2001
Messages
15,548
I believe what you want is &H26BC34 - unless you got that from Excel in which case (don't hold me to this) it might be &H34BC26. As I recall, Access RGB is in a different order than Excel's RGB. But it will be one or the other.
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
Help me I am still stuck still if I have a hover color of #319f34 how do I tell VBA on GotFocus of the button to use the same color and then on lost focus tell VBA to return the button to its original color. What is the code I would be using?
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,644
Did the code in post 4 not work (modified to your needs)?
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
yes but only if I use the command Me.cmdCloseForm.BackColor = VB(something) but the colors I want to use is #319f34 how do I tell VBA to use that color I don't know what its name is. and then on lost focus tell the button to turn back to its original color of. #3B4DD1
 

seeker9969

New member
Joined
Jan 25, 2020
Messages
23
I finally got it LOL

Private Sub cmdSaveRecord_GotFocus()
Me.cmdSaveRecord.BackColor = RGB(49, 159, 52)
End Sub

Private Sub cmdSaveRecord_LostFocus()
Me.cmdSaveRecord.BackColor = RGB(59, 77, 209)
End Sub
Is there a way to use hex colors in VBA
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom