1
votes

I was looking for the answer to this problem for couple of days. I have my main form "frmAddContact" with navigation sub form called "NavigationSubform". All text fields have glow effect added by placing a button under and changing visibility of the button OnGotFocus and OnLostFocus events. All works perfectly fine when I'm moving in and out on the main form and also when I move to sub form, but the problem occurs when I move from sub form to Main form - focus on sub form remains, so glow is visible on sub form and main form.

How can I remove the focus when I select text box in the main form?

Each text box has following code:

Private Sub [TextBoxName]_GotFocus()
Glow Me.[TextBoxName], Me.[ButtonName], True
End Sub

Private Sub [TextBoxName]_LostFocus()
Glow Me.[TextBoxName], Me.[ButtonName], False
End Sub

Glow method code sits in Module:

Sub Glow(ctlText As Control, ctlShadow As Control, TurnOn As Boolean)
If TurnOn = True Then
    ctlText.BorderColor = RGB(102, 175, 233)
    ctlShadow.Visible = True
Else
    ctlText.BorderColor = RGB(228, 228, 228)
    ctlShadow.Visible = False
End If
End Sub

Two text boxes with glow Here

1

1 Answers

0
votes

I think the issue is the subform itself hasn't really lost focus. You should be able to force the glow to be removed by running your glow code from the Main form's Textbox GotFocus event.

It is a bit tricky, but check out many online resources about referencing subforms from forms.
This is a good one to start with

The rule is you basically have to refer to the main form first, then the subform , then the control

If you do this when the text box gets focus it should clear the subform control's glow

Private Sub [TextBoxName]_GotFocus()
   Glow Forms![frmAddContact]![NavigationSubform].Form.[TextBoxName], _   
        Forms![frmAddContact]![NavigationSubform].Form.[ButtonName], False
   Glow Me.[TextBoxName], Me.[ButtonName], True
End Sub