Article ID: 210236 - View products that this article applies to.
This article was previously published under Q210236
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.mdb).
For a Microsoft Access 97 version of this article, see 136127
When you are creating new records by using a form, you may want to speed the data entry process by having fields in the new record fill automatically with values from the previous record. This article shows you how to create a sample Visual Basic for Applications function called AutoFillNewRecord() that enables you to fill selected fields (or all fields) in a new record with values from the previous record automatically.
Note This article explains a technique that is demonstrated in the sample file that is named FrmSampl.mdb.
For additional information about how to obtain this sample file, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/233324/ )The Microsoft Access 2000 sample forms database available in Download Center
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.
One technique that you can use to speed repetitive data entry for the field that contains the insertion point is to press CTRL+APOSTROPHE (') to retrieve the value from the previous record.
Another technique is to use the AutoFillNewRecord()function described later in this article. You can call this function from a form's OnCurrent property event procedure to fill all the fields in a new record using data from the previous record. If you want to fill only selected fields, you can create a text box and set the DefaultValue property with a semicolon-delimited list of control names to automatically fill, for example:
To create and use the AutoFillNewRecord() function, follow these steps:
Text box: ----------------------------------------------- Name: AutoFillNewRecordFields Visible: No DefaultValue: Phone;Company Name;City;State;Zip
For more information about the For Loop, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type For Each...Next Statement in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Contact us for more help
Connect with Answer Desk for expert help.