473,383 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

avoid duplicate entry in vb6

sir,
i am developed a application in visual basic 6.0 but at last iam facing a problem when a user search data that display in all textboxes form ms access database.
but when he click on save button the old data (searched) also saved or when he enter the new data it gets saved any problem to this i have following code
Visual basic 6.0
do while not rs.eof
if rs.field(1).value=txtcustname.text then
msgbox " this is duplicate entry"
end if
exit sub
loop
but in this case if the entry is already present in database it hang in loop and application hangs up
i want quick solution plz send me solution as early as possible
thanks you
Nov 23 '14 #1
4 3545
twinnyfo
3,653 Expert Mod 2GB
prafulla1978,

I'm not sure how your code could be hanging up, since you tell your code to exit the sub no matter what the result of the If...Then is. You also do not appear to be doing anything else once a duplicate is found, other than notifying the user. You are also never moving to the next record.

So, it is unclear as to what the problem is with your code, as it appears there are many.
Nov 24 '14 #2
kadghar
1,295 Expert 1GB
Try a FOR EACH, and leave the EXIT SUB inside the IF (I'd rather use an EXIT FOR).
Nov 24 '14 #3
i have deloped the above code :
Expand|Select|Wrap|Line Numbers
  1. dim name as string
  2. dim str as string
  3. dim rs as recordset
  4. dim rs as new adodb.recordset
  5. str="Select name from table1 where name='" & txtname.text &"'"
  6. rs.open str,db, adopenstatic , adlockoptimistic
  7. name=rs.field(1).value
  8. if name=txtname then
  9. exit sub
  10. else
  11. rs.addnew
  12. end if
Nov 25 '14 #4
twinnyfo
3,653 Expert Mod 2GB
prafulla,

First, please use code tags when posting code to this forum.

Second, if the code above is what you are actually using, one of the biggest glaring problems I see is that you are using the reserved word "Name" as one of your field names. This can cause very many unexpected errors and problems when writing code (and is probably a significant contributing factor to your problem here.

I would recommend changing the "Name" Field in table1 to something like "UserName", just to make sure the VBA can differentiate between that field and another reserved word.

Hope this hepps!
Nov 25 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Geetu | last post by:
I am trying to jar up a file and getting this exception, not sure what could be wrong. The same piece of code works fine in few machines but there is one machine where this piece of code gives this...
0
by: jjliu | last post by:
i have a table with two fields (id and myfield). id is a primary key not nll auto_increment, and myfield is set as unique... Due to unique setting for myfield, if i try to insert the duplicate...
0
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
3
by: patelxxx | last post by:
I'm trying to update a template on our Content Management System, however getting the following error. I know its difficult to know what the problem is without looking at the PERL coding, however...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
1
by: waqasahmed996 | last post by:
Hi I am facing a strange problem. I have a duplicate entry message even though i am using IGNORE in query. My query is insert ignore into table1 select * from table2 Error is: Error Code :...
2
by: neelsfer | last post by:
I have a problem with duplicate entries. I can't get this code to work. I have one other request. When the message box appears, i would like the "racefinishtime" record in this same table to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.