ACC2000: "You Cannot Add or Change a Record..." Error Message When You Try to Add a Product to a New Order (319320)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q319320
Moderate: Requires basic macro, coding, and interoperability skills.

SYMPTOMS

When you try to add a product to a new order in the Orders form in the Order Entry sample database, you may receive an error message similar to the following:
You cannot add or change a record because a related record is required in table 'Orders'.

CAUSE

This behavior occurs if you do not click an item in the Employee combo box before you try to add a product to the Products subform.

RESOLUTION

To resolve this issue, use either of the following methods.

Method 1: Modify the On Enter Event Procedure of the Order Details Subform

To modify the On Enter property of the subform control, follow these steps:
  1. Open the Orders form in Design view.
  2. Click the subform control, and then click Properties on the View menu.
  3. Click the Event tab, click the On Enter property, and then click the Build button.
  4. Replace the existing event procedure with the following one:
    Private Sub Order_Details_Subform_Enter()
    On Error GoTo Err_Order_Details_Subform_Enter
    If IsNull(Me![OrderID]) Then
       Me![OrderDate] = Date
       Forms!Orders!OrderID.SetFocus
       DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
       Forms!Orders![Order Details Subform].SetFocus
    End If
    
    Exit_Order_Details_Subform_Enter:
    Exit Sub
    
    Err_Order_Details_Subform_Enter:
    MsgBox Err.Description
    Resume Exit_Order_Details_Subform_Enter
    
    End Sub
    					
  5. Quit the Visual Basic Editor, and then open the Orders form in Form view.

Method 2: Click an Item in the Employee Combo Box

Before you try to add a product in the Products Subform, click an item in the Employee combo box.

Modification Type:MinorLast Reviewed:1/7/2006
Keywords:kberrmsg kbprb KB319320