 |
| 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
|
|
|
|

January 18th, 2007, 12:49 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

January 18th, 2007, 01:08 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Donevco,
What is your primary key field?
Kevin
dartcoach
|
|

January 18th, 2007, 01:14 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Email address.
|
|

January 18th, 2007, 01:20 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Is this problem relating to your previous post?
Kevin
dartcoach
|
|

January 18th, 2007, 01:25 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I see it as a different problem. However it does occur in that form.
|
|

January 18th, 2007, 01:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
This form, does it allow users to add, update and delete records? If so, how do you determine what they are doing?
Kevin
dartcoach
|
|

January 18th, 2007, 01:37 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 18th, 2007, 01:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|
 |