Error 3201: Cannot add record in child form/table
Assistance needed for Button Code on Parent Form:
Assistance needed for Button Code on Parent Form.
Syntax problem with the following line in adding record and/or updating value of CustomerID in child table:
Me.CustomerID = Forms.Item(FrmCustomerDetail).Controls(ActionLog). Value
Background:
FrmCustomer (parent) is based upon TblCustomers. The button on this form opens FrmActionLog (child), which is based upon TblActionLog. (FrmActionLog is a separate pop-up form and not an embedded sub-form)
TblCustomers holds customer contact information. TblActionLog holds telephone call information/history. There is a one-to-many relationship between TblCustomers and TblActionLog and linked by CustomerID.
Problem Statement:
After adding a new customer to TblCustomers (parent) there is not a matching record in TblActionLog (child) with the matching and new CustomerID.
When a customer record is displayed in FrmCustomer and the user clicks on the button to open FrmActionLog the detail record displays CustomerID = 0. Then, when trying to input information into FrmActionLog (and into TblActionLog) and Error message 3201 is returned.
[Note: The error message in this instance appears to be misleading. âYou cannot add or change a record because a related record is required in table âTblCustomersâ. Actually, the problem is that there is no matching record in TblActionLog !!
A little something is needed for the Button Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CustomerID = 0 Or IsNull(Me.CustomerID) Then
Me.CustomerID = Forms.Item(FrmCustomerDetail).Controls(ActionLog). Value
'I do not understand the syntax for "Controls" part of the line above. I'm trying to obtain the CustomerID value from the FrmCustomerDetail and place it into Me.CustomerID (e.g. FrmActionLog). In this example "ActionLog" is the name of the button on the FrmCustomerDetail.
End If
End Sub
Guidance and Suggestions will be very much appreciated !!
Thank you!
Jerry
|