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...:
Expand|Select|Wrap|Line Numbers
- 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...