Cursor position on continuous form

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Cursor position on continuous form

Post by Carol W. »

Access 2003

I have a continuous form. The header contains several unbound fields used for allowing the user to enter parameters. The detail section contains four updatable fields -- (1) date in (2) time in (3) date out (4) time out. I would like to have the cursor positioned at the "date in" field of the "next" record" after the current record has been updated.

How can I do this in VBA code?

Thanks, in advance.
Carol W.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Cursor position on continuous form

Post by HansV »

If you have set the Cycle property of the form to "All Records" (this is the default setting) and made the "date in" control the first one in the tab order of the detail section, the focus should automatically be on the "date in" control of the next record when the user tabs out of the current one.

If you want the focus on the "date in" control whenever the user moves to a different record, you can use code in the On Current event of the form:

Code: Select all

Private Sub Form_Current()
  Me.txtDateIn.SetFocus
End Sub
where txtDateIn is the name of the control bound to the "date in" field. If this name contains spaces or punctuation, enclose it in square brackets:

Code: Select all

  Me.[Date In].SetFocus
Best wishes,
Hans

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Re: Cursor position on continuous form

Post by Carol W. »

Thanks, Hans :thankyou:

We had the tab order incorrectly set in both the header and the detail. We were unable to straighten that out easily so we ended up putting the SetFocus statement that you suggested in the OnCurrent event. Works great!
Carol W.