![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Fellows, Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? Thanks in advance for any help or ideas. Arsene |
#3
| |||
| |||
|
|
Arsene (AT) selenium (DOT) net wrote: Fellows, Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? Thanks in advance for any help or ideas. Arsene You could try this. Place the following code in the form's code module Private Function SetBackground(blnSet As Boolean) As Long Dim strCtl As String Dim lngColor As Long lngColor = IIf(blnSet, 16711935, 16777215) strCtl = Me.ActiveControl.Name Me(strCtl).BackColor = lngColor End Function Then highlight all of the textbox controls in the form. Open up the property sheet. In the GotFocus event enter =SetBackground(True) and in the LostFocus event enter =SetBackground(False) Run and test. |
#4
| |||
| |||
|
|
Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? |
#5
| |||
| |||
|
|
Arsene (AT) selenium (DOT) net wrote: Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? I think you can avoid using Me by using: Screen.ActiveForm.ActiveControl But for text and combo boxes you don't need any code. You can use Comditional Formatting's Field Has Focus option instead. |
#6
| |||
| |||
|
|
On Sun, 10 Apr 2011 12:50:49 -0500, Salad <salad (AT) oilandvinegar (DOT) com wrote: Arsene (AT) selenium (DOT) net wrote: Fellows, Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? Thanks in advance for any help or ideas. Arsene You could try this. Place the following code in the form's code module Private Function SetBackground(blnSet As Boolean) As Long Dim strCtl As String Dim lngColor As Long lngColor = IIf(blnSet, 16711935, 16777215) strCtl = Me.ActiveControl.Name Me(strCtl).BackColor = lngColor End Function Then highlight all of the textbox controls in the form. Open up the property sheet. In the GotFocus event enter =SetBackground(True) and in the LostFocus event enter =SetBackground(False) Run and test. Worked beautifully, Salad, this is great. Tried to stick the same code as a Public Function in a module to make it available to all forms, but the "Me" in: strCtl = Me.ActiveControl.Name keeps it from running as there's no underlying objetcs to the module. Thanks !!!!!!!!!!!!!! |
#7
| |||
| |||
|
|
Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. |
#8
| |||
| |||
|
|
Arsene (AT) selenium (DOT) net wrote: Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. Make them all the highlight color then set all to transparent backgrounds. The one with focus will highlight with no code at all. If you insist the ones without focus have a white background just put white rectangles behind them. |
#9
| |||
| |||
|
|
Arsene (AT) selenium (DOT) net wrote: On Sun, 10 Apr 2011 12:50:49 -0500, Salad <salad (AT) oilandvinegar (DOT) com wrote: Arsene (AT) selenium (DOT) net wrote: Fellows, Have an application with numerous forms, each containing multiple bound text boxes. As the user tabs from field to field down any of the forms, I want to change the selected text box background color from a white default to a different color, to make it easy to spot which field has the focus at any time. I am currently accomplishing this by using each text box's GotFocus and LostFocus events, each with a different textbox.backcolor color code which works perfectly. This, however, requires an enormous amount of labor in a large application, as two events have to be set for every single text box. Is there a way to accomplish the same with one block of code elsewhere in the application, hopefully public code in a module? Thanks in advance for any help or ideas. Arsene You could try this. Place the following code in the form's code module Private Function SetBackground(blnSet As Boolean) As Long Dim strCtl As String Dim lngColor As Long lngColor = IIf(blnSet, 16711935, 16777215) strCtl = Me.ActiveControl.Name Me(strCtl).BackColor = lngColor End Function Then highlight all of the textbox controls in the form. Open up the property sheet. In the GotFocus event enter =SetBackground(True) and in the LostFocus event enter =SetBackground(False) Run and test. Worked beautifully, Salad, this is great. Tried to stick the same code as a Public Function in a module to make it available to all forms, but the "Me" in: strCtl = Me.ActiveControl.Name keeps it from running as there's no underlying objetcs to the module. Thanks !!!!!!!!!!!!!! You could try this. Put this in a Module. Public Function SBC(strForm As String, blnSet As Boolean) As Boolean Dim strCtl As String Dim lngColor As Long lngColor = IIf(blnSet, 16711935, 16777215) strCtl = Forms(strForm).Form.ActiveControl.Name Forms(strForm)(strCtl).BackColor = lngColor End Function Then highlight the textboxes and enter in the GotFocus even =SBC("Form4",True) and =SBC("Form4",False) in the ListFocus event |
![]() |
| Thread Tools | |
| Display Modes | |
| |