Add Button on Form go to field

  • Thread starter Thread starter ScottB
  • Start date Start date
S

ScottB

I have created a button (using the wizard) to add a new
record to a form. For the most part, this is simple and
works well. My 'problem' is that I'd like the cursor to
start in the first field of the new record. Instead, the
user has to first click on a field before beginning data
entry. I've been trying to use simple VBA code like
Private Sub Form_AfterInsert()
DoCmd.GoToControl BIO_FNAME
End Sub
to move to the field but it seems to always recognize the
previous record's data in that field, instead of on the
new blank record. Any suggestions? Scott
 
Put this code on the form's OnCurrent event:

Private Sub Form_Current()
If Me.NewRecord = True Then Me.FirstControlName.SetFocus
End Sub


Where FirstControlName should be replaced by the name of the control that
you want to get the focus when the new record starts.
 
Ken, you're brilliant! Worked like a charm.
-----Original Message-----
Put this code on the form's OnCurrent event:

Private Sub Form_Current()
If Me.NewRecord = True Then Me.FirstControlName.SetFocus
End Sub


Where FirstControlName should be replaced by the name of the control that
you want to get the focus when the new record starts.

--
Ken Snell
<MS ACCESS MVP>




.
 
Back
Top