Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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?

Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:44 PM.


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