Access World Forums

Access World Forums (https://www.access-programmers.co.uk/forums/index.php)
-   VB.NET (https://www.access-programmers.co.uk/forums/forumdisplay.php?f=73)
-   -   griddataview duplicate data message (https://www.access-programmers.co.uk/forums/showthread.php?t=305273)

Ryobi 05-29-2019 07:14 PM

griddataview duplicate data message
 
Hello,


I have this issue that perhaps somebody can solve using a gridataview in Vb,net. The column of cells need to be unique, so I am checking for duplicates when the cells are changed or added. If the cell are duplicates then I want to cell to be reverted to the old value. I have my code below


For Each row In DgvDataRecords.Rows
If ItemName = row.Cells("Card ID").Value Then
Itemcnt = Itemcnt + 1
If Itemcnt > 1 Then
' MessageBox.Show("Item already exists, can not be add. ")
DgvDataRecords.CurrentCell.Value = Oldvalue
Exit Sub

End If
If Itemcnt = 1 Then
Rowfound = DgvDataRecords.Rows.IndexOf(row)
End If
End If
Next



The code works except that I want to put a message to tell the user that the cells are duplicate. This the remarked line ' MessageBox.Show("Item already exists, can not be add. "). The problem that I have is that when the old value is restored the error message is displayed again as it was part the cell. Is there a way to suppress the second error message ?


Thank you

rpeare 05-31-2019 06:29 AM

Re: griddataview duplicate data message
 
Instead of displaying the message box immediately, you can store an 'errorsfound' variable (1 or 0) then at the end of your code running display the message box if the errorsfound value is non zero. Would also allow you do things like capture all the errors on your form and display them in a single message as opposed to getting a pop up for each error encountered.

Ryobi 06-08-2019 10:01 AM

Re: griddataview duplicate data message
 
Thank you for the information. You are correct about a single error message, that is what I was trying to do, however my dilemma is that I need to stop when it get the one that I that is being checked (the current record) or by pass that in case the current record is not a new record. Hope this makes sense.


All times are GMT -8. The time now is 11:52 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World