PREVENTING Duplicate Entries in Access

Results 1 to 3 of 3

Thread: PREVENTING Duplicate Entries in Access

  1. #1
    Join Date
    Dec 1969

    Default PREVENTING Duplicate Entries in Access

    I have a table in an Access DB that contains user information. userID, Email (which I use as their username), password, first name, and last name.<BR><BR>I want to prevent a user from creating two profiles or accounts with the same email and last name.<BR><BR>Currently the primary key is an autonumber field: userID.<BR><BR>So the table might hold this record:<BR><BR>userID = 1<BR>email =<BR>first name = paul<BR>last name = haines<BR>password = howdy<BR><BR>I want to prevent a user from accidentally or unintensionally creating a second instance of their profile. I want to avoid the following:<BR><BR>userID = 2<BR>email =<BR>first name = paul<BR>last name = haines<BR>password = howdy<BR><BR>See, the same user but a DIFFERENT userID... How can I keep them from doing this?<BR><BR>Would setting the primary key to both the userID field AND the email field and setting the key to allow no duplicates do the trick?<BR><BR>Patrick<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: PREVENTING Duplicate Entries in Access

    I&#039;d check if it already exists<BR><BR>rsCheck = "Select count(id) From &#060;table&#062; where Email = &#039;" &email & "&#039;"<BR><BR>If rsCheck.recordcount &#062; 0 Then<BR> &#039; Duh your already here DumbAss<BR>Else<BR> &#039;ok to insert<BR>End if

  3. #3
    Join Date
    Dec 1969

    Default WK's idea good, but...

    ...if you want to really PREVENT the occurrenct, just set the email field to be "no duplicates allowed" in Access!<BR><BR>Bring up Access and open the DB.<BR><BR>Select the "Table design view" for your "users" table.<BR><BR>Click on the field "login".<BR><BR>Look down at the bottom in the "General" tab.<BR><BR>See the line that says "Indexed". Right now, it says "No."<BR><BR>Change it to "Yes (No Duplicates)".<BR><BR>Save everything. <BR><BR>Presto. <BR><BR>Now even if you mess up and don&#039;t have a test like WK proposes, the DB itself will protect you and throw an error if you ever try to insert (or update) to create a duplicate.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts