Hello everyone! Can somebody please help me with this... I have a VB program that inputs Name and Address. I've made a database in MS Access using ADO Control:
Table Name: Contacts
Fields are: ID, CompanyName, CompanyAddress
My only problem is that how can I find duplicate entries in the CompanyName field. I have an ADD command button when adding new Company Name from a textbox. What I would like to do is that before the program add the Company Name in the textbox to the database, I wanted to check first if there is any duplicate. Ive made a code but it wont work...: - Private Sub cmdAdd_Click()
-
-
adoWC.Recordset.MoveFirst
-
-
while not adoWC.Recordset.EOF
-
-
if txtCompanyName.text = adoWC.Recordset("CompanyName") then
-
Msgbox("Duplicate Entry")
-
Exit Sub
-
else
-
adoWC.Refresh
-
adoWC.Recordset.MoveFirst
-
adoWC.Recordset.AddNew
-
adoWC.Recordset("CompanyName") = txtCompanyName.Text
-
adoWC.Recordset("CompanyAddress") = txtCompanyAddress.Text
-
adoWC.Recordset.Update
-
adoWC.Recordset.MoveFirst
-
Exit Sub
-
end if
-
-
adoWC.Recordset.MoveNext
-
-
End Sub
Can somebody help me... Thanks...
5 13836
if you just want that no body enter duplicate name of company
just make company name field in access as a primary key.
Hello everyone! Can somebody please help me with this... I have a VB program that inputs Name and Address ...
Why do you need to find duplicates? I agree with the previous poster, declaring a primary key in Access is the easiest way to prevent this. However, if there's a fair amount of data, this could corrupt some fields.
The other way to do it is nested loops. The pseudo code is below: (letters correspond to indents (loops))
1. FOR EACH ITEM
2a. store next item in a string variable (call it strCurrent).
3a. FOR EACH ITEM
4b. compare current item with strCurrent (above)
5b. if duplicate, set a boolean to true (break loops)
6c. (if needed) add to string of duplicates
7b. else, get next
8b/a. END, END
Depending on the amount of data, this may take a while to run but it's quicker then 1 guy sitting reading through everything.
The 2nd part to this is adding a new record.
1. FOR EACH ITEM
2a. compare with input, if same - break loop, error
3a. else - add to DB
4. END
Hope this helps.
- LB
No need to go for all the tricky logics . I will give you a simple solution.
When the user clicks add read value from textbox and compare it with database records using count() . If count is 0 insert the record if 1 then you exit and display a message saying the entry already exists.
hi muddasirmunir, LacrosseB0ss, debasisdas thanks to all your reply and help.
i have a sample code here debasisdas is this what you mean? - Dim noDUP as integer
-
-
nuDUP = "SELECT COUNT(CompanyName) FROM Contacts WHERE CompanyName = txtCompanyName.text"
-
-
if nuDUP = 0 then
-
adoWC.Refresh
-
adoWC.Recordset.MoveFirst
-
adoWC.Recordset.AddNew
-
adoWC.Recordset("CompanyName") = txtCompanyName.Text
-
adoWC.Recordset("CompanyAddress") = txtCompanyAddress.Text
-
adoWC.Recordset.Update
-
adoWC.Recordset.MoveFirst
-
else
-
Msgbox("Already Exists.")
-
-
End if
Thanks Again...
everything here looks good except for keeping txtCompanyName.text in the quotations in your SQL statement will look for that string, not the value in the text box. You'll need to say " ... WHERE CompanyName = " & txtCompanyName.text & ";".
Other than that, looks good. By the way, nice catch debasisdas. Much easier solution. (Y)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Barbara |
last post by:
Hi,
I have an sql database that has the primary key set to three fields,
but has not been set as unique(I didn't create the table).
I have 1 record that has 2 duplicates and I am unable to delete...
|
by: Brian |
last post by:
I'm trying to find a way to search multiple tables for the same record.
Say I have 3 tables all with a name column, I need to search all 3
tables and find matching names. Is there an easy way to...
|
by: steevp |
last post by:
Hi,
Please excuse the newbie type question, but I am wracking my brains to
solve what should be a simple query.
I have three fields in a table F1, F2, F3. Any of the fields may
contain...
|
by: Jameel |
last post by:
how do i find duplicate records in ASP.net/ADO.net , i know how to do it in
classic asp, anything appreciated code,tutorial links etc..
(if rs.eof then
add record
else
error message
end if
)
|
by: Booster |
last post by:
Hi
I am a beginner
working with VB.net
Ho to:
find data in another column using the index number "ParamID", also the
possibility to updata the data in "ParamVal".
This is a Parameter table ...
|
by: Carroll |
last post by:
I'm looking for a way in SQL to find duplicate records in a single
table, that are the same based on 3 columns, regardless of what is in
the other columns in the duplicate records. I would like to...
|
by: nethravathy |
last post by:
Hi,
The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not.
I tried with following query
1)SELECT...
|
by: mabubakarpk |
last post by:
Hello every one,
I Have table e.g
EmpID TDate Status
***************************************
1 01-01-08 AB
1 02-01-08 AB
1 ...
|
by: anantha raman |
last post by:
Hai,
I am a beginer in Developing ASP.NET webpage.
I want to restrict duplicates while uploading the excel data and to inform the user that the perticular cell in excel contains duplicate value...
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |