Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2004, 09:56 AM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Record to table from form AlForum29 Access VBA 2 January 2nd, 2013 09:46 PM
Using DetailsView control to add record to Child megnin ASP.NET 1.x and 2.0 Application Design 0 September 5th, 2008 03:37 PM
Add record form bunkerbang Access VBA 5 September 12th, 2007 12:17 AM
Add record to another table with radiobutton Dejitan ASP.NET 1.0 and 1.1 Basics 8 January 11th, 2007 09:24 AM
ADO record copy and add to table Freddyfred Access 2 February 16th, 2005 10:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.