Microsoft KB Archive/168191

= Microsoft Knowledge Base =

PRB: Cannot Trap Error Number 1884 on Form
Last reviewed: May 8, 1997

Article ID: Q168191

The information in this article applies to:


 * Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 5.0a

SYMPTOMS
You cannot trap duplicate key errors such as the following:

Uniqueness of index "name" is violated (Error 1884) when the error is caused by a user's interaction with a Grid on a form.

RESOLUTION
For a workaround that uses record buffering, place the following code in the Valid method of a TextBox of the Grid:

IF .NOT. TABLEUPDATE *Invalid Primary Key Trapped here since Error method of Grid does not. =AERROR(arrtemp) =MESSAGEBOX('Error:'+STR(arrtemp(1,1));          +CHR(13)+arrtemp(1,2),0,'Error') RETURN 0 ENDIF

STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Steps to Reproduce Behavior
  Issue the following two lines in the Command window: CREATE DATABASE primerr CREATE TABLE tblprim (fld1 c(3) PRIMARY KEY, fld2 c(2), fld3 c(3))  Add several records to the above table. Create a new form by clicking New from the File menu. Click Form in the dialog box and click the New File button. When the form comes up, right-click on the form and select DataEnvironment from the Shortcut menu. When the DataEnvironment window comes up, right-click in the window and select Add Table from the Shortcut menu. When the Open dialog box appears, select the table created in Step 1. Drag and drop the table from the DataEnvironment to the form to make a Grid.</li> Run the form and type in a duplicate value for a record in fld1 column and move off the record.</li> Note Visual FoxPro presents an error message.</li> Choose Revert and close the form.</li> Modify the form.</li> On the property sheet, select the combo at the top and choose the Grid.</li> Find the Grid's Error method and add in a WAIT WINDOW command.</li> Repeat step 9.</li></ol>

In version 3.0 and 3.0b, step 15 behaves the same as it did when step 9 was executed.