No duplication records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!

I have one form with:
cboName, to choose name and cmdNewName to open F_AddName and requery combo.
Work fine.

Now, it would like:
1 - Not to allow duplication of names in F_AddName;
2 - Through cmdDelName, to be able to erase records of defined chosen name.

Thanks in advance.
an
 
Not allowing duplicates is easy: just put a Primary Key on the name in the
underlying table, and it won't be possible to have duplicates. However, how
will you know whether two people with the same name are really a duplicate
or not? George Foreman named all five of his sons George: how will you know
which one is which?

Assuming you know the primary key of the record you want to delete, one way
is:

CurrentDb.Execute "DELETE FROM MyTable WHERE MyKey = " & KeyValue,
dbFailOnError

If the key value is text, you need to put quotes around the value you're
passing:

CurrentDb.Execute "DELETE FROM MyTable WHERE MyKey = " & Chr(34) & KeyValue
& Chr(34), dbFailOnError

(This assumes you're not using Access 2000 or 2002. If you are, then with
any code module open, select Tools | References from the menu bar, scroll
through the list of available references until you find the one for
Microsoft DAO 3.6 Object Library, and select it. If you're not going to be
using ADO, uncheck the reference to Microsoft ActiveX Data Objects 2.1
Library)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top