Adding New Records in the HRActionEntry Form

Unlike Chapter 14's frmHRActions form, the Record Source for the main frmHrActionEntry form is a query. The query design takes advantage of Access' row fix-up feature when you add a new record to the HRActions table in the form. Row fix-up works in this case, because the source of the qryHRActions query's EmployeeID column is the HRActions table.

For a review of row fix-up in one-to-many queries, see "Taking Advantage of Access's Row Fix-Up Feature," p. 431.


To add a new record to the HRActions table, do the following:

  1. graphics/new_record.gif Open frmHRActionEntry in Form view, and click the tentative append (new) record button to add a new record. All data disappears from the form.

  2. Type a number (other than 1, the default) in the [Employee]ID text box; for this example type 5. Press Tab or Enter to add data in the query columns from the Employees table and default values from the HRActions table to the form's controls (see Figure 15.59).

    Figure 15.59. Adding a new record and typing an employee ID in the ID text box fills the form with employee data and default values from the qryHRActions query.

    graphics/15fig59.jpg

  3. Make selections in the combo boxes, change the default dates, if necessary, and add a note regarding the action. Choose Records, Save Record or, if your cursor isn't in the Notes multi-line text box, press Shift+Enter to save the record (see Figure 15.60). Shift+Enter in a multi-line text box adds a newline character and doesn't save the record.

    Figure 15.60. Completing the record addition requires only a few combo box selections, changes to dates, and an optional note.

    graphics/15fig60.jpg

  4. Verify that you added the record correctly by selecting the employee for whom you added the action in this case Steve Buchanan in the Find combo box. Click the History tab to display the employees entries (see Figure 15.61). The History subform's snapshot Recordset must be refreshed to display the added record.

    Figure 15.61. After you refresh the History subform by selecting the employee in the Find combo box, the newly added record appears.

    graphics/15fig61.jpg

At this point in its development, frmHRActionEntry would be dangerous to release for use by data entry operators. For example, all fields in the main form are updatable. Thus, an operator could change the FirstName, LastName, and other values of the Employees table, as well as the EmployeeID for an existing HRActions record. You can set the Locked property to Yes for all controls linked to the Employees table, but you can't lock the EmployeeID text box that's required to specify the EmployeeID of a new record. You can control the locked status of form controls by adding VBA event-handling code for the form's Before Insert and After Insert events.

Tip

You can make frmHRActionEntry safe for data entry operators by setting the Data Entry property of the form to Yes. Specifying Data Entry prevents operators from viewing existing records and only allows them to enter new records. In this case, you must change the Recordset Type property value of the subform to Dynaset, and set the AllowEdits, AllowDeletions, and AllowAdditions property values to Yes. Otherwise, the added record won't appear in the History subform.




Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net