Highlighting active control in a form

WJReid

Active Member
Joined
Jul 26, 2002
Messages
317
Hi All,

Can anyone tell me how to highlight the active control on a form, either the backcolour or the border colour, as you tab through the form?

Thanks for any help in advance

Regards,

Bill
 
Alrighty y'all, I'm sure I'm going nuts! :grin:

The following works exactly as expected in xl '97:<code>
Private Sub ComboBox1_Enter()
ComboBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ComboBox1.BackColor = -2147483643
End Sub

Private Sub ListBox1_Enter()
ListBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub ListBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ListBox1.BackColor = -2147483643
End Sub

Private Sub OptionButton1_Enter()
OptionButton1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub OptionButton1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
OptionButton1.BackColor = &H8000000F
End Sub

Private Sub TextBox1_Enter()
TextBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub TextBox1_exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.BackColor = -2147483643
End Sub</code>

This time, I made sure to code what ought to be grey, grey and white, white. Don't know why this works for me and not y'all...

This fires correctly every time when I code it correctly (right control name in the procedure, right event name).

If you have two textboxes make sure all of them are coded correctly, e.g.,

Code:
Private Sub TextBox1_Enter()
TextBox1.BackColor = RGB(255, 128, 128)
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.BackColor = -2147483643
End Sub

Private Sub TextBox2_Enter()
TextBox2.BackColor = RGB(255, 128, 128)
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.BackColor = -2147483643
End Sub

If you don't replace textbox1 with textbox2, you will have issues....

Regards, Nate
This message was edited by NateO on 2002-11-21 01:52
 
Upvote 0
Hi Nate,

Thanks again for your help.

I have 30 text boxes or combo boxes on my form and I have named them ct1 to ct30 for ease of adding the contents in them to a database through a loop.

I tried your code and for some reason it does not work with the first 4 boxes, either text or combo, it then works with the next 4 and then does not work after that.I have exactly the same code in for each control.

Does it have anything to do with calling them ct1 etc. rather than ComboBox1 or TextBox1?

Regards,

Bill
 
Upvote 0
NateO I would really Like to see this work on enter and exit, If you could send me a working workbook, to technix@writeme.com I would greatly appreciate it

Derrick

again I am using xl97 with XP
 
Upvote 0
I have 30 text boxes or combo boxes on my form and I have named them ct1 to ct30 for ease of adding the contents in them to a database through a loop.

Does it have anything to do with calling them ct1 etc. rather than ComboBox1 or TextBox1?

Howdy Bill, no it shouldn't. We discuss the ease of looping through ct1-ct30 vs. combobox1-combobox30 another time perhaps...

I've sent you both an example via e-mail, in hopes of proving my sanity. Let me know if it doesn't function as expected.

Also, if you want to get a quick handle on RGB's from a cell's colorindex, the following thread may be of interest:

http://216.92.17.166/board/viewtopic.php?topic=25599&forum=2

Don't try to call it in a procedure, it'll need parsing, but, it'll crank out the didgits for you.
 
Upvote 0
Nate,

This reply should restore your sanity however, it increased my insanity, Oddly enough your userform functioned as it should changing color on enter, and back on exit, However using the same exact code for my userform does not

Im still playing with it

Thank you for the help

Derrick
 
Upvote 0
On 2002-11-21 18:50, technix wrote:
Nate,

This reply should restore your sanity however, it increased my insanity, Oddly enough your userform functioned as it should changing color on enter, and back on exit, However using the same exact code for my userform does not

Im still playing with it

Thank you for the help

Derrick

So, I'm not crazy and you (or your Computer) is? :grin:

ROFL!!

Re-look at your code, you may have the wrong control name in the right procedure, etc.... (I did this while coding it last night after a few beverages...)

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-11-21 21:19
 
Upvote 0
Hi Nate,

My computer must also be crazy!!!

Your code worked perfectly on the example you sent. On my computer, it still didn't work for the first 4, worked for the next 4, then stopped working.

I think I'll have to start from scratch with the form and use your code to see if it makes any difference.

Thanks once again Nate.

Regards,

Bill
 
Upvote 0
So, I'm not crazy and you (or your Computer) is? :grin:

ROFL!!

Re-look at your code, you may have the wrong control name in the right procedure, etc.... (I did this while coding it last night after a few beverages...)

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-11-21 21:19

Well I wasnt Crazy until I attempted to do this on my crazy computer. Everything Appears to be correct not sure

Derrick
 
Upvote 0
Well I wasnt Crazy until I attempted to do this on my crazy computer. Everything Appears to be correct not sure

Derrick

Hey Dude, I opened your .frm file, I didn't even see an enter or exit event. Which is a problem. :eek:

Now I'm going crazy. :sad:

Please post the problematic code to this thread so the board can evaluate both our sanity levels. :grin:

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-11-22 14:06
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top