dbTalk Databases Forums  

Access 2003 - easing the task of changing a selected text box background color

comp.databases.ms-access comp.databases.ms-access


Discuss Access 2003 - easing the task of changing a selected text box background color in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Access 2003 - easing the task of changing a selected text box background color - 04-10-2011 , 12:13 PM






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

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text boxbackground color - 04-10-2011 , 12:50 PM






Arsene (AT) selenium (DOT) net wrote:

Quote:
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.

Reply With Quote
  #3  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text box background color - 04-10-2011 , 01:17 PM



On Sun, 10 Apr 2011 12:50:49 -0500, Salad <salad (AT) oilandvinegar (DOT) com>
wrote:

Quote:
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 !!!!!!!!!!!!!!

Reply With Quote
  #4  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text box background color - 04-10-2011 , 02:27 PM



Arsene (AT) selenium (DOT) net wrote:
Quote:
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.

--
Marsh

Reply With Quote
  #5  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text box background color - 04-10-2011 , 02:54 PM



On Sun, 10 Apr 2011 14:27:28 -0500, Marshall Barton
<marshbarton (AT) wowway (DOT) com> wrote:

Quote:
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.
Conditional formatting!! But of course!!!

Thanks again, Salad.

Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text boxbackground color - 04-10-2011 , 04:43 PM



Arsene (AT) selenium (DOT) net wrote:

Quote:
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

Reply With Quote
  #7  
Old   
Rick Brandt
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text box background color - 04-10-2011 , 07:58 PM



Arsene (AT) selenium (DOT) net wrote:
Quote:
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.

Reply With Quote
  #8  
Old   
John Spencer
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text boxbackground color - 04-11-2011 , 08:36 AM



One small modification to Rick Brandt's suggestion.
Instead of putting white rectangles behind each control, just set the Back
Color of the section to white.


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 4/10/2011 8:58 PM, Rick Brandt wrote:
Quote:
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.

Reply With Quote
  #9  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Access 2003 - easing the task of changing a selected text box background color - 04-15-2011 , 12:08 PM



On Sun, 10 Apr 2011 16:43:03 -0500, Salad <salad (AT) oilandvinegar (DOT) com>
wrote:

Quote:
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
That is clever, Salad, will give it a try in my next Access
application.

Thanks!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.