How can I stop the same record being saved twice

Steve78

Registered User.
Local time
Yesterday, 23:48
Joined
Feb 24, 2006
Messages
13
Hi can anyone help please!

I'm writing a course registration Db. I have a have 3 tables at the moment tblContacts [ContactID], [FName], [SName], [Etc..] tblCourseRegistration[RegID] [ContactID][CourseID] and
tblCourses[CourseID] [CourseName] [Etc...]

These are all linked on a tabbed form. I have found that the same Contact can sign up for the same course twice. I need to stop this happening. Is there an easy way to prevent this or do I have to write a query that runs before the save command to prevent this?

Thanks in advance person with sore head!
 
Thanks for that Pat it worked a treat! No more duplicates.

Just a small secondary issue, I was wondering whether it would be possible to replace the Access warning message with something a bit friendlier like -
"Sorry, you are already booked in for this course"
Is this possible?
 
In your error handler just trap error 3022 and display your own message.
 
Thanks for the advice RuralGuy could you just be a little more explicit or point me to a page that explains exactly how to do this.

Cheers
 
You could put code in the OnError event of the form:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 3022 Then
   MsgBox "Sorry, this number has already been used!"
End If
Response = acDataErrContinue
End Sub
 
Thanks for that I tried placing it on the OnError event of the form but it does not seem to work. I still get the same message. How do I find out what the error code is for a particular message?
 

Users who are viewing this thread

Back
Top Bottom