Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change back color of field on got focus 1

Status
Not open for further replies.

mrgrogro

Technical User
Jan 8, 2005
58
US
I have a form that is kind of "busy." I'd like to change the back color of the field when the field has the focus. I've tried several things but seem to be too lame to figure it out...oh, and we use Access 97 at work.

Can I please get a little help?


Sincerest thanks in advance!
 
Hi there

Try the following:-

Code:
Private Sub FirstNames_GotFocus()

    Me.FirstNames.BackColor = 16777215

End Sub

to change color when entering the field and

Code:
Private Sub FirstNames_LostFocus()

    Me.FirstNames.BackColor = 12632256

End Sub

to change it back when exiting the field.

Just an idea!

Regards

Tony
 
Thanks Tony. Your advise was not only just what I was looking for, it was the fastest I've ever received a response. Thanks a million!
 
For a more generic way of handling this, try
Code:
Private Function ChangeColor()
[COLOR=green]'Function to change the background colour for the active control
' on a form.  In the GotFocus and LostFocus events of all controls, enter the function
' = ChangeColor()
'  Written by G.Hubbell 2001

'NB:  Add the function to the form's module - this function will not run from
' a module as curently written.[/color]



On Error Resume Next

Dim ctl As Control

    Set ctl = Me.ActiveControl
    If ctl.BackColor = 16777215 Then
        ctl.BackColor = 10092543
    Else
        ctl.BackColor = 16777215
    End If
    
End Function
You can set your desired colours by changing the backcolour numbers to whatever you wish to use.

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top