ACC2000: Error When You Add Record to a Form That Is Based on a Stored Procedure

ID: Q248095


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access project (.adp).


SYMPTOMS

When you add a record to a form in a Microsoft Access project (ADP) file, you receive the message:

The data was added to the database but the data won't be displayed in the form because it doesn't satisfy the criteria in the underlying record source.


CAUSE

The form is based on a stored procedure that contains multiple tables.


RESOLUTION

Set the ResyncCommand property of the form to an SQL statement that selects the same fields as the stored procedure, and parameterize the primary key field of the table that is designated as the Unique Table. To use the ResyncCommand property of the form to work around this problem, follow these steps:

  1. Follow steps 1 through 10 of the "Steps to Reproduce Behavior" section later in this article.


  2. Click OK to clear the error message returned by Microsoft Access.


  3. Open the form in Design view.


  4. Set the ResyncCommand property of the form to the following SQL statement:


  5. SELECT Customers.CompanyName AS CompanyName, Customers.ContactName AS
    ContactName, Orders.OrderID, Orders.CustomerID, Orders.EmployeeID,
    Orders.OrderDate FROM Customers INNER JOIN Orders ON Customers.CustomerID =
    Orders.CustomerID WHERE Orders.OrderID = ? 
  6. Save the CustomerOrders form, and then close it.


  7. Open the CustomerOrders form in Form view.


  8. Follow steps 8 through 10 of the "Steps to Reproduce Behavior" section later in this article.


Note that the record is saved successfully without generating an error.


MORE INFORMATION

The ResyncCommand property allows you to write an SQL statement that Microsoft SQL Server executes to fix up data from the primary table whenever the user modifies a value in a foreign key field and saves the record. The SQL statement must select the same fields from the primary table that are included in the stored procedure.

The SQL statement must also contain a WHERE clause that passes ? as a parameter marker for the primary key column from the primary table in the stored procedure. This is necessary so that Microsoft SQL Server can resync the form to the same record as the one modified in Microsoft Access.

A general rule is that you should set the ResyncCommand property to the same SQL statement as the stored procedure being used as the record source, minus the WHERE clause being used in the stored procedure. Then add a WHERE clause to the SQL statement that parameterizes the primary key columns from the table designated in the UniqueTable property of the form.

Steps to Reproduce Behavior

  1. Open an Access project connected to the sample NorthwindCS database on Microsoft Data Engine (MSDE) or Microsoft SQL Server.


  2. Create and save the following stored procedure:


  3. 
    Create Procedure CustomerOrders
    As
    SELECT 
       Customers.CompanyName AS CompanyName, 
       Customers.ContactName AS ContactName,
       Orders.OrderID, 
       Orders.CustomerID,
       Orders.EmployeeID, 
       Orders.OrderDate
    FROM Customers INNER JOIN
       Orders ON Customers.CustomerID = Orders.CustomerID 
  4. In the Stored Procedures list, click CustomerOrders, and then click AutoForm on the Insert menu.


  5. On the View menu, click Design View.


  6. Set the UniqueTable property of the form to Orders.


  7. Save the form as CustomerOrders.


  8. Open the CustomerOrders form in Form view.


  9. Move to a new record.


  10. Enter the following values.
    Field Value
    CustomerID ALFKI
    EmployeeID 3
    OrderDate 12/31/1999
    Note that the other fields are not be editable because they are not in the Orders table, which is currently designated as the Unique Table of the form.


  11. On the Records menu, click Save Record.


Note that you receive the error message mentioned in the "Symptoms" section of this article.


REFERENCES

For more information about the ResyncCommand property, click Microsoft Access Help on the Help menu, type ResyncCommand in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For additional information about using the ResyncCommand property in a form, click the article number below to view the article in the Microsoft Knowledge Base:

Q239886 ACC2000: How to Simulate AutoLookup with a Stored Procedure in Access Client/Server

Additional query words: prb

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.