Keeping the focus on the same field as in the previous record

  • Thread starter Thread starter Bill Reed via AccessMonster.com
  • Start date Start date
B

Bill Reed via AccessMonster.com

I have a very long subform on a main form. My user wants to keep the focus on
the same field in this long form as he navigates back and forth between
records. By default, when he navigates to a different record, the focus goes
to the 1st field in the form header. It is a relatively easy matter to write
an on current event to set the focus on a given control, but how do I
determine where the focus was in the previous record in order to set it?

Thanks,

Bill
 
Barada... nikto

OK. I finally got back to that form I was working on. What the user wants to
do is navigate to the next record behind the form and have the focus set to
the same control as was active in the previous record (screen.ActiveControl.
Properties("Name")).
Are you suggesting a global variable (Public strCtl as String) that would be
updated in the setfocus event of every control on the form (there are about
50 controls on the form)? As in:

strCTL = Screen.ActiveControl.Properties("Name")

I was hoping for some event of the form that could pass the name to the
variable when the record changes. Or is there some simpler way to remain in
the control as the user navigates through the records?

I have an On Load event as follows:

Private Sub Form_Load()
Me.txtSheet.SetFocus
End Sub

It sets the focus to the text control txtSheet, but I didn't think that event
would fire going to the next record. After all, the form isn't loading again,
is it? I would expect the On Current event to fire, not the On Load event.

Thanks,

Bill
 
I am not absolutely positive, because I have never done this, but if you are
moving from form to form, you might try putting it in the Lost Focus event of
the form to determine which control was active when you moved to the other
form, then a goto acitve contrl in the Got Focus event. You probably need to
check for a zero length string in the Got Focus.
 
Back
Top