rsanglim
asked on
BackColor of ActiveControl
Hello, Experts! I'm using the following code in a module to 'highlight' the active field of a multi-tabbed form. In each field's GotFocus I have =Blue_BackGround(), in LostFocus I have =White_BackGround(). Works great, except opening the form produces "Run-time error '2474': The expression you entered requires the control to be in the active window." If I un-comment On Error..., seems to work ok but I'm wondering if that's the best way to deal with the problem. I've tried 'forcing' the ActiveControl to a field of the first tab, but can't seem to make that work. Thanks...Scott
Option Compare Database
Global Const PURE_WHITE = 16777215
Global Const PALE_BLUE = 16777175
Public Function White_Background()
Screen.ActiveControl.BackC olor = PURE_WHITE
End Function
Public Function Blue_BackGround()
'On Error Resume Next
Screen.ActiveControl.BackC olor = PALE_BLUE
End Function
Option Compare Database
Global Const PURE_WHITE = 16777215
Global Const PALE_BLUE = 16777175
Public Function White_Background()
Screen.ActiveControl.BackC
End Function
Public Function Blue_BackGround()
'On Error Resume Next
Screen.ActiveControl.BackC
End Function
While a form is openning, and the Onfocus event of the first control is triggered, there is not yet an active control.
At the point you are right now, I will use the On Error resume next statement.
An alternative, if you have Access 2000 or more recent, will be to define conditional formating. But for 500 fields, I am not certain of the impact on performance...
At the point you are right now, I will use the On Error resume next statement.
An alternative, if you have Access 2000 or more recent, will be to define conditional formating. But for 500 fields, I am not certain of the impact on performance...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ahmedbahgat - I like your solution...clean and simple, no errors to deal with on form load. Thanks!
no problems, cheers
ASKER