Microsoft KB Archive/114882

= ACC: No Difference Between dbConsistent and dbInconsistent =

Article ID: 114882

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q114882



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use the dbConsistent and dbInconsistent (or DB_CONSISTENT and DB_INCONSISTENT in version 2.0) constants with the OpenRecordset method in code to create a recordset, it appears not to have any effect on the editability of the recordset. That is, after creating a recordset using the dbConsistent constant, you can change fields from the "one" side of a one-to-many join.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.



CAUSE
If you select Enforce Referential Integrity and Cascade Update Related Fields in the Relationships window for the one-to-many relationship in question, the difference between dbConsistent and dbInconsistent is nullified.



STATUS
This behavior is by design.



MORE INFORMATION
If you change the relationship so that referential integrity is not enforced, you can see the difference between the two constants. The following example demonstrates the difference using the one-to-many relationship between the Customers and Orders tables in the sample database Northwind.mdb (or NWIND.MDB in version 2.0). Those tables are joined on the CustomerID field.

NOTE: In version 2.0, there is a space in the Customer ID field.

The following steps demonstrate the difference between the constants by first opening a recordset using the dbInconsistent constant, changing the CustomerID, opening the recordset again using the dbConsistent constant, and then changing the CustomerID again:

 Start Microsoft Access and open the sample database Northwind.mdb (or NWIND.MDB in version 2.0). Create a new query and add the Customers and Orders tables. Drag the CustomerID field from both tables to the query grid. Save the query as ConsistentDemo.  Create a new module and enter the following code.

In Microsoft Access 7.0 and 97: Function ConsistentDemo Dim rs As Recordset, db As Database Set db = CurrentDB Set rs = db.OpenRecordset("ConsistentDemo", dbOpenDynaset,_        dbInconsistent) rs.FindFirst "[Customers].[CustomerID]='ALFKI'" rs.Edit rs![Customers.CustomerID] = "ALFKJ" rs.Update rs.FindFirst "[Customers].[CustomerID]='ALFKJ'" rs.Edit rs![Customers.CustomerID] = "ALFKI" rs.Update Set rs = db.OpenRecordset("ConsistentDemo", dbOpenDynaset,_         dbConsistent) rs.FindFirst "[Customers].[CustomerID]='ALFKI'" rs.Edit rs![Customers.CustomerID] = "ALFKJ" rs.Update rs.FindFirst "[Customers].[CustomerID]='ALFKJ'" rs.Edit rs![Customers.CustomerID] = "ALFKI" rs.Update rs.Close db.Close MsgBox "Test complete." End Function In Microsoft Access 2.0:

NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic. Function ConsistentDemo Dim rs As Recordset, db As Database Set db = CurrentDB Set rs = db.OpenRecordset("ConsistentDemo", DB_OPEN_DYNASET,_        DB_INCONSISTENT) rs.FindFirst "[Customers].[Customer ID]='ALFKI'" rs.Edit rs![Customers.Customer ID] = "ALFKJ" rs.Update rs.FindFirst "[Customers].[Customer ID]='ALFKJ'" rs.Edit rs![Customers.Customer ID] = "ALFKI" rs.Update Set rs = db.OpenRecordset("ConsistentDemo", DB_OPEN_DYNASET,_         DB_CONSISTENT) rs.FindFirst "[Customers].[Customer ID]='ALFKI'" rs.Edit rs![Customers.Customer ID] = "ALFKJ" rs.Update rs.FindFirst "[Customers].[Customer ID]='ALFKJ'" rs.Edit rs![Customers.CustomerID] = "ALFKI" rs.Update rs.Close db.Close MsgBox "Test complete." End Function  Run the function by typing the following line in the Debug window (or Immediate window in version 2.0), and then pressing ENTER:

? ConsistentDemo

Note that the code runs without any errors. You are able to change data whether the recordset is opened consistently or inconsistently.</li> Select the Database window, and then click Relationships on the Tools menu (or on the Edit menu in version 2.0).</li> Double-click the join line between the CustomerID fields in the Customers and Orders tables.</li> Click to clear the Enforce Referential Integrity check box, and then click OK.</li> Run the ConsistentDemo function again by typing the following line in the Debug window and then pressing ENTER:

? ConsistentDemo

Note that this time you receive the error message:

Field can't be updated

Because referential integrity is not being enforced for the relationship, the dbInconsistent constant has the expected effect.</li></ol>

NOTE: When you reset the relationship between the Customers and Orders tables, be sure to select the Cascade Update Related Fields check box in addition to the Enforce Referential Integrity check box.

<div class="references_section">