PDA

Click to See Complete Forum and Search --> : Check Duplication data entries in DBGrid


zoiz
Jun 29th, 1999, 09:43 PM
i am using unbound dbgrid to allow user to add, edit or delete any data about the purchase order details.

the problem is the item ID entered should not be duplicated since it is a unique key in the database.

i got problem when trying to write the code to check the row entries in the Item ID column each time the user enter that data.

can someone help ?

thanks

David Ridgway
Jun 30th, 1999, 12:01 AM
In the Before Column Update Event run a SQL statement to applies only to the column in question. Check to see if entered value alrady exists in the table and clear the entered value and send a message box to notify the user.

ie:
Private Sub grdYourGridName_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)

'The Column # for ID is 1

Select Case ColIndex

Case = 1

Set Recordset = "Select ID from TableName
Where ID = grdYourGridName.col(1).Text

If Not Recordset.BOF and Not Recordset.EOF Then

Cancel = True
msgbox "Duplicate ID Number Entered"

End If

Hope this helps

David Ridgway
fdridgway@halifax.osp.com