Go Back   Access World Forums > Apps and Windows > VB.NET

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-29-2019, 07:14 PM   #1
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
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

Ryobi is offline   Reply With Quote
Old 05-31-2019, 06:29 AM   #2
rpeare
Newly Registered User
 
Join Date: Sep 2016
Posts: 18
Thanks: 0
Thanked 3 Times in 2 Posts
rpeare is on a distinguished road
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.
rpeare is offline   Reply With Quote
Old 06-08-2019, 10:01 AM   #3
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
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.

Ryobi is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate check query showing non-duplicate data ScrmingWhisprs Queries 8 08-10-2016 04:01 PM
Message upon duplicate first, last, MI pseudonymn Forms 11 06-12-2013 07:10 AM
Message box if duplicate value skwilliams Forms 16 09-29-2009 10:07 AM
Duplicate value message sloaner14 Forms 6 03-12-2004 01:10 AM
Data not saving and duplicate values message pbuethe General 8 02-27-2004 12:24 PM




All times are GMT -8. The time now is 11:04 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


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