Keep focus on a row in adatasheet

B

BrunoKP

I have a button by which a row is added in a subform with a datasheet. But
this datasheet has a bounded parent datasheet where the focus currently is on
a certain row. After the adding of a row in the child datasheet, the focus of
the parent datasheet jumps back to the first row.
How can I get back to the same row in the parent datasheet after the button
event?
 
A

Allen Browne

The main form should not jump back to the first row unless you do something
such as requerying it.

If the main form and subform are both bound to the same table, you might be
issuing a Requery so the main form gets to hear about the record in the
subform. IME, this is not a good design. When you build this kind of form,
the default linkage between parent and child means you get really messed up
autonumbers. That's in addition to the concurrency problems you have started
to find (new row or edit not showing without requery, #Deleted when you
delete a row, memo fields that won't edit correctly in some versions of
Access, etc.)

Access 2007 does provide a view for you that solves this kind of thing:
Split form view. If you are not using this version, there are alternatives,
such as using a list box on the main form for navigation rather than a
subform. There are still some concurrency issues to solve, but it won't mess
up as much.

If you really want to proceed, you will need to save the primary key value
to a variable before you issue the requery. Then FindFirst that value in the
RecordsetClone of the form and set the Bookmark, or explicitly RunCommand
acRecordsGotoNew if the primary key was a null (indicating the new record
row.)
 

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