Return Focus to the previous object.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box in a Form that on the Enter event of the TextBox it opens a
Popup Form. How do I immediately return the Focus back to the TextBox on the
Main Form using code when the Popup form opens?

Thank you,

Steven
 
I have a text box in a Form that on the Enter event of the TextBox it opens a
Popup Form. How do I immediately return the Focus back to the TextBox on the
Main Form using code when the Popup form opens?

Thank you,

Steven
 
This is not what I want. I want the PopUp Form to open and immediateley with
the PopUp Form Open I want the focus to go back to the control on the main
form that had the focus when the PopUp Form opened.

Thanks,

Steven
 
I tried that but the focus stays with the PopUp Form. I dont see why it
wont let the focus go back to the Main Form and to the TextBox I want.
 
Steven said:
I tried that but the focus stays with the PopUp Form. I dont see
why it wont let the focus go back to the Main Form and to the TextBox
I want.

It's not as simple as you'd think. I've found this way to do it:

Set the popup form's TimerInterval to 1. Then have code like this in
the popup form's module:

'----- start of code -----
Option Compare Database
Option Explicit

Dim mfrmPrev As Form

Private Sub Form_Close()

Set mfrmPrev = Nothing

End Sub

Private Sub Form_Open(Cancel As Integer)

Set mfrmPrev = Screen.ActiveForm

End Sub


Private Sub Form_Timer()

Me.TimerInterval = 0
mfrmPrev.SetFocus

End Sub

'----- end of code -----

There ought to be an easier way, but I haven't found it yet.
 
Back
Top