简体   繁体   中英

In MS Access, how to select record on form1 after adding from form2?

This is my scenario (MS Access 2007):

On Form1 I have a list of records (Orders). Form1 has a button that launches Form2.

Form2 is used for creating new Orders. The "Save" button on Form2 uses VBA to save the record, close the form and requery Form1:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCloseWindow
Forms!Orders.Requery

The next step I'd like to be able to do is have the new record selected automatically on Form1. My guess is it's somehow done with DoCmd.FindRecord ? I can't figure it out -- any help is very appreciated.

Thanks, Stewart

The answer would depend on whether the application has a single user or multiple users. In a multiuser scenario, simply getting the most recently added Order would not necessarily return the one YOU have just entered. But if it's only you, getting the most recently added value would do that.

You can find the row with the max(orderid) if you're using an autoincrementing key; or find the row with the max(orderDateTime) if your orders are timestamped; or simply have the datasource for the Orderslist form be sorted by either of those values, descending, and reposition to the first record after a Requery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM