Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 18th, 2007, 12:49 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Duplicate Primary Key

I'm addressing the situation when the user accidently enters a duplicate record. Assess takes them through a clumsy process, advising that the record can't be entered, ending by closing the form.

This table has a single primary key field. I'd like to check for a duplicate as soon as the field is entered, warn the user, and allow her to back out or, possible, reset the form. Anybody have some good code?

  #2 (permalink)  
Old January 18th, 2007, 01:08 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Donevco,

What is your primary key field?

Kevin

dartcoach
  #3 (permalink)  
Old January 18th, 2007, 01:14 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Email address.

  #4 (permalink)  
Old January 18th, 2007, 01:20 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is this problem relating to your previous post?

Kevin

dartcoach
  #5 (permalink)  
Old January 18th, 2007, 01:25 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see it as a different problem. However it does occur in that form.

  #6 (permalink)  
Old January 18th, 2007, 01:31 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

This form, does it allow users to add, update and delete records? If so, how do you determine what they are doing?

Kevin

dartcoach
  #7 (permalink)  
Old January 18th, 2007, 01:37 PM
Authorized User
 
Join Date: Nov 2006
Location: Evergreen, CO, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again, the problem doesn't relate to any particular form. However, in this "People" table, I don't allow deletions. For updates (please see my previous posting) I use a control to unlock the form for updates. To add, I generally use the navigation button to get to eof. I haven't turned this form over to the user yet. Happily, only one user is responsible for maintaining this table.

  #8 (permalink)  
Old January 18th, 2007, 01:59 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK.

In the after update event of the forms email, try this:

   Set rs = New Recordset
   mySQL = "Select * From People Where email = " & "'" & Me.email & "';"
   rs.Open mySQL, con, adOpenDynamic, adLockOptimistic
   With rs
      If .BOF = False Or .EOF = False Then
         msgbox "You Have Entered a Duplicate Email."
         me.email.setfocus
      End If
   End With
   rs.close
   set rs = nothing

Kevin

dartcoach


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting duplicate values in primary key column, Shuchik SQL Server ASP 1 August 31st, 2007 05:38 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Checking for duplicate primary key in Access Indo77 ASP.NET 2.0 Basics 2 November 29th, 2006 12:19 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.