New record on subform

R

RGBrighton

I have a subform ('continuous forms' view) linked to the parent through the
'StaffID' field. The recordsource for the subform is a table.
For neatness I do not want an extra, blank 'new' record showing permanently
so have set 'AllowAdditions' to 'no'.
But the user will occasionally need to add/delete records on the subform.
For deletions I include record selectors - so I can select a record and
press delete.
For additions I have a button that runs this code (found from this
invaluable community):

Set rs = Me.RecordsetClone
With rs
.AddNew
!StaffID = Me.Parent("StaffID")
.Update
.Bookmark = .LastModified
End With
rs.Close

The new record is created fine. But I cannot make the new record be
selected automatically. I want the user to be able to type straight into the
new fields without having to click into them first.
Is there something missing? Or is there a better way to achieve this?

Any advice gratefully received.
Richard
 
K

Ken Snell MVP

Add a SetFocus step after the rs.Close step so that you put the focus into
the control that is to be first for data entry. And you need to move the
form to that new record:

Set rs = Me.RecordsetClone
With rs
.AddNew
!StaffID = Me.Parent("StaffID")
.Update
.Bookmark = .LastModified
End With
Me.Bookmark = .Bookmark
rs.Close
Me.NameOfFirstControl.SetFocus
 
R

RGBrighton

Many Thanks Ken, That has solved the problem.

(But note: "me.bookmark = .bookmark" goes before the "End With" statement or
use rs.bookmark)

Very frustrating that the help page does not include this step!

Thanks again, I really value the excellent help offered here.
Richard
 
K

Ken Snell MVP

RGBrighton said:
Many Thanks Ken, That has solved the problem.

(But note: "me.bookmark = .bookmark" goes before the "End With" statement
or
use rs.bookmark)

Good catch... my mistake when typing the "air code".

Very frustrating that the help page does not include this step!

Thanks again, I really value the excellent help offered here.

You're welcome. Good luck.
 

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