NO duplicate entries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • calebm12
    New Member
    • Mar 2006
    • 5

    #1

    NO duplicate entries

    Quick Question. I gotta a database with fields firstname, lastname, and hobby, etc. I dont want to allow duplicate entries for the name. For instance....no john smith twice....but there can be a repeated john. Well i created a multi-field index and that is fine....the problem is that my form is very long....there is lots of data to enter and the user could very well end up adding all this data then going to close it and find out it wont work. I want the user to know that it is a duplicate name right after they enter the first and last name. Can you help me with this. I tried to put
    DoCmd.RunComman d acCmdSaveRecord
    in the after update field for first and last name. But it is giving me a runtime error. Can anyone help me? I know my code must be wrong.
    Thanks in advance
  • CaptainD
    New Member
    • Mar 2006
    • 135

    #2
    Looks like you're using MS Access (You should give details such as program, language, code snippets if available etc. when posting a question) Try creating a Query:
    Code:
     SELECT COUNT(*) FROM YourTable WHERE FirstName = Trim(txtFirstName.Text) AND LastName = trim(LastName)
    Then once the person exits the txtFirstName or txtLastName have your form run a Function that runs the Query and returns the number of records. (0 for none, meaning no match.) Then go through an IF THEN to give notice of a duplicate entry.

    Comment

    Working...