Got/Lost Focus and highlighting the field

Mike Smith

Registered User.
Local time
Today, 20:01
Joined
Sep 22, 2000
Messages
20
I want to highlight a form's field whenever it has the focus. It's easy enough to do by assigning code to the GotFocus Event for the field (Me.ActiveControl.Backcolor=10079487) but I don't want to have to go in to all 235 fields to do it. Can I assign this change globally and if so how? Thanks!
 
Here's a way to cycle through groups of fields on a form. You could easily modify this to go though all the fields, but usually I've found that there are some that I do not want to change.

Here goes. Use the "tag" property for each field that you want to change, and give them a common name (for example, "SalesFields"). Then, in your code, do this:

Dim frmMyForm As Form
Dim ctlMyCtls As Control

Set frmMyForm = Forms!fMyForm
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "SalesFields" Then
ctlMyCtls..Backcolor=10079487
End If
Next ctlMyCtls

Set frmMyForm = Nothing
 
I selected the appropriate fields and set the "Tag" property to "HighlightFields". I then entered the following code in the Class Module:

Option Compare Database
Option Explicit

Dim frmMyForm As Form
Dim ctlMyCtls As Control

Set frmGeneral = Forms!frmMyForm
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "HighlightFields" Then
ctlMyCtls.BackColor = 10079487
End If
Next ctlMyCtls

Set frmMyForm = Nothing


And while I get no errors, it doesn't change the background from white to peach. Any thoughts?

Thanks!
 
Hmmm...exactly when do you want the background to change? You need to put (or call) the code in the proper event.

Also, are you familiar with the debug window? I'd set a breakpoint & then watch to see if the code is ever executed.
 
I want the background to change color if and only if the field has the focus. I tried inserting a call statement but don't think I got it right. Unfortunately I don't know much at all about the Debug window...
 

Users who are viewing this thread

Back
Top Bottom