Add Button on Form go to field

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
 
K

Ken Snell

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.
 
S

ScottB

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>




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top