A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Control Background Color



 
 
Thread Tools Display Modes
  #1  
Old May 21st, 2009, 06:14 PM posted to microsoft.public.access.forms
John Lane
external usenet poster
 
Posts: 69
Default 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  
Old May 22nd, 2009, 12:30 AM posted to microsoft.public.access.forms
Scott Whetsell, A.S. - WVSP
external usenet poster
 
Posts: 34
Default 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  
Old May 22nd, 2009, 01:59 AM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default 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  
Old May 22nd, 2009, 02:55 PM posted to microsoft.public.access.forms
John Lane
external usenet poster
 
Posts: 69
Default 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  
Old May 22nd, 2009, 10:49 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default 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

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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.