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
- Open an Access project connected to the sample NorthwindCS database on Microsoft Data Engine (MSDE) or Microsoft SQL Server.
- Create and save the following stored procedure:
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
- In the Stored Procedures list, click CustomerOrders, and then click AutoForm on the Insert menu.
- On the View menu, click Design View.
- Set the UniqueTable property of the form to Orders.
- Save the form as CustomerOrders.
- Open the CustomerOrders form in Form view.
- Move to a new record.
- Enter the following values.
Collapse this tableExpand this table
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. - On the Records menu, click Save Record.
Note that you receive the error message mentioned in the "Symptoms" section of this article.