Microsoft KB Archive/234217

= ACC2000: Fill Record with Data from Selected Record on a Data Access Page =

Article ID: 234217

Article Last Modified on 6/30/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q234217



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
When you are entering new records in a data access page, you may want to speed the data entry process by having fields in the new record fill automatically with values from the current record. This article shows you how to create script that enables you to fill selected fields (or all fields) in a new record with values from the current record automatically.



MORE INFORMATION
You can create your own Add New Record button on a page to fill all the fields in a new record using data from the previous record.

To create a page that automatically fills the new record, follow these steps:  Open the sample database Northwind.mdb or NorthwindCS.adp. In the Database window, click Pages under Objects, and then click New. In the New Data Access Page box, click AutoPage: Columnar, click Order Details in the Choose the table or query/view where the object's data comes from box, and then click OK. On the View menu, click Design View. Set the Height property of the Header: Order Details section to 2in. In the toolbox, click the Command Button, and then click somewhere below the Discount field. If the Command Button Wizard appears, click Cancel.</li>  Set the following properties for the command button: <pre class="fixed_text">  ID: cmdAddNewRec InnerText: Add New Record </li> On the Tools menu, point to Macro, and click Microsoft Script Editor.</li>  Type the following into the Script Editor between the HEAD tags: <SCRIPT language=vbscript>

</SCRIPT> </li>  In the Script Outline window, expand the Client Objects and Events folder. Expand cmdAddNewRec, and then double-click onclick. Type the following script.

NOTE: If the Script Outline window is not displayed, point to Other Windows on the View menu, and then click Script Outline. <SCRIPT event=onclick for=cmdAddNewRec language=vbscript>

</SCRIPT> </li> On the File menu, click Save All. In the File name box, type dapAutoFill, and then click Save.</li> On the File menu, click Exit.</li> On the View menu, click Page View. Note that the page shows that there is a total of 2155 records.

</li> Browse to a record, for example, Order Details 7 of 2155. Note the values of the fields for record #7.

</li> Click the Add New Record button that you created in step 6. Note that you are now on record 2156 of 2156, and this new record has the same field values that record #7 had.

</li> NOTE: You need to change the ProductID to a different value, 33 for example, before you can save the new record. Otherwise, you are trying to create a duplicate record.</li></ol>

This functionality cannot be applied directly to the navigation bar that was created with the page. For this reason, you need to create your own Add New Record button. It is recommended that you also add you own First Record, Previous Record, Next Record, Last Record buttons, and so on, and that you then remove the navigation bar from the page.

Keywords: kbhowto kbdap kbdapscript KB234217

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.