If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Control Background Color
Is there a way entirely change the background color when a control has focus?
That is, the field I have is green backgound with black forecolor. I changed the background on the fly to red, but the when the field has focus, data in it was surrounded by black, with red characters. The rest of the field is red. What I want is the black to go away and leave the white letters. |
#2
|
|||
|
|||
Control Background Color
Using the GotFocus and LostFocus events would be my suggestion.
Private Sub ControlName_GotFocus() Me.ControlName.BackColor = vbBlack Me.ControlName.ForeColor = vbRed End Sub Private Sub ControlName_LostFocus() Me.ControlName.BackColor = vbGreen Me.ControlName.ForeColor = vbBlack End Sub Change ControlName as appropriate and you can use any numeric color value in place of the vb colors. I believe the most common colors and be used as I showed above. "John Lane" wrote: Is there a way entirely change the background color when a control has focus? That is, the field I have is green backgound with black forecolor. I changed the background on the fly to red, but the when the field has focus, data in it was surrounded by black, with red characters. The rest of the field is red. What I want is the black to go away and leave the white letters. |
#3
|
|||
|
|||
Control Background Color
Scott's code will work for Single View forms, but not for Datasheet or
Continuous View forms. Simpler to do, and workable for all types of forms is to use Conditional Formatting off the toolbar. In Design View, select the control, then goto Format - Conditional Formatting Under Condition select "Field has focus" Now simply set the fore and background colors you want. -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200905/1 |
#4
|
|||
|
|||
Control Background Color
The only thing wrong with these solutions is what happens when you put the
cursor (ie., has focus) in the control - you get three colors - the color you set it to, then a reverse set of colors of the actual string of data - I guess the form software is trying to highlight and reverse video the character string - so you can end up with three colors! "Linq Adams via AccessMonster.com" wrote: Scott's code will work for Single View forms, but not for Datasheet or Continuous View forms. Simpler to do, and workable for all types of forms is to use Conditional Formatting off the toolbar. In Design View, select the control, then goto Format - Conditional Formatting Under Condition select "Field has focus" Now simply set the fore and background colors you want. -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200905/1 |
#5
|
|||
|
|||
Control Background Color
So you don't want the data to be selected on entering the field. There's a
couple of ways you can handle this. If you want this to be the default behavior for all fields on all forms, in Design View you can Goto Tools - Options - Keyboard and set "Behavior on entering field" to either go to the beginning of the field or go to the end of the field. If this doesn't suit, you can do it on a field-by-field basis: To set it to the end of the data: Private Sub YourTextboxName_GotFocus() YourTextboxName.SelStart = Len(Me.YourTextboxName) End Sub and Private Sub YourTextboxName_Click() YourTextboxName.SelStart = Len(Me.YourTextboxName) End Sub To set it to the beginning of the dat, replace YourTextboxName.SelStart = Len(Me.YourTextboxName) with YourTextboxName.SelStart = 0 -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200905/1 |
Thread Tools | |
Display Modes | |
|
|