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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Active input control to change colors on OnGotFocus 1

Status
Not open for further replies.

sterlecki

Technical User
Oct 25, 2003
181
US
BACKGROUND:

I have a function taken from the O'Reilly Access Cookbook publication that causes an input control on a form to change background color.

It is placed in the OnGotFocus event of the control and a similar function is placed in the OnLostFocus event of the control.


Private Const conYellow = 7467773
Private Const conWhite = 16777215

Public Function SpecialEffectEnter()
On Error GoTo HandleErr

'Set the control's background color to yellow

Screen.ActiveControl.BackColor = conYellow

ExitHere:
Exit Function

HandleErr:
'MsgBox Err & ": " & Err.Description
Resume ExitHere
End Function


Public Function SpecialEffectExit()
On Error GoTo HandleErr

'Set the control's background color to white

Screen.ActiveControl.BackColor = conWhite

ExitHere:
Exit Function

HandleErr:
'MsgBox Err & ": " & Err.Description
Resume ExitHere
End Function


In addition in the OnOpen event of the form they say to place the following code:

me.setfocus

This prevents Access from using the Screen.ActiveControl before the form has fully loaded according to the CookBook.

This all works fine if it is a simple form ie. no page tabs etc.

[red]PROBLEM:[/red]

[highlight aqua]I have a form that has several tabbed pages, and each page has a subform. I cannot get this to work without an error message: "The expression you entered requires the control to be in the active window:

I have tried many configurations too numerous to mention but
I cannot figure out what I should be referencing for the me.setfocus part of this routine. I don't know if it's how I'm referencing them or if I'm referencing the wrong object.
Object names are as follows:

Form: "Main Form"
Page: "pgWellHeader"
Subform "Frm_WellHeader"[/highlight]

Any thoughts?


 
Assuming v2000 or later this is so very simple using Conditional Formatting, and best of all, you can do as many textboxes as you want, in one fell swope!

In Design View, select all textboxes you want to exhibit this behavior.

Goto Format - Conditional Formatting

Under Condition1 select "Field has focus"

Select the background color

You're done.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Missinglinq

Yes I became aware of that yesterday while experimenting with 2007. A star for you. However now it's the challenge. I want to find out how to make this method work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top