Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Forms

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-30-2009, 04:17 AM
BigBear BigBear is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2009
Posts: 9
BigBear is on a distinguished road
Default If duplicate record, go to original record

Hello,
Thanks in advance for your help.

When a duplicate record is added, I want a custom error message to be displayed, and then the user to be taken to the original record.

Basically if If DataErr = 3022 (error code for duplicates) Then display custom message and go to original record.


I have attached a test database as well as my code below.

Here is the code I have on the Form's On Error event.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
'If an error occurs because of missing data in a required field
'display our own custom error message
Const conErrRequiredData = 3314
If DataErr = conErrRequiredData Then
MsgBox ("All required fields must be filled in")
Response = acDataErrContinue
Else
'Display a standard error message
Response = acDataErrDisplay
End If

'If an error occurs because of a duplicate record.
If DataErr = 3022 Then
Response = acDataErrContinue
MsgBox "This appendix already exists. Press Esc to cancel and then modify your entry."
End If

End Sub
Attached Files
File Type: zip Test.zip (493.1 KB, 18 views)
Reply With Quote
  #2  
Old 03-30-2009, 07:27 AM
BigBear BigBear is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: Mar 2009
Posts: 9
BigBear is on a distinguished road
Default I got the solution

I got it with help from Prevent Duplicate Information from being entered into a Microsoft Access form | Database Solutions for Microsoft Access | databasedev.co.uk.
I was able to take the code/example and modify it for my needs.
Thank you

By placing the following code sample into the Before Update event of the Student Number field in the main form (top half of the form), this will prevent the duplication, raise a custom error message and return the user to the original record for the Student:


Private Sub strStudentNumber_BeforeUpdate(Cancel As Integer)
'*********************************
'Code sample courtesy of srfreeman
'*********************************
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strStudentNumber.Value
stLinkCriteria = "[strStudentNumber]=" & "'" & SID & "'"
'Check StudentDetails table for duplicate StudentNumber
If DCount("strStudentNumber", "tblStudentDetails", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Student Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to record of original Student Number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
Attached Files
File Type: zip Prevent_Duplicates_2000.zip (85.1 KB, 19 views)

Last edited by BigBear; 03-30-2009 at 08:50 AM. Reason: Solution didn't display correctly
Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate the record in form and subform to a different table mwillis929 Forms 0 01-06-2009 11:17 AM
using value from previous record dollars Queries 0 12-10-2008 12:30 PM
Deleting Record Contents, not complete record... Charles Waters Access 2 06-24-2008 10:00 AM
How to Find a Record lschlitt Programming 2 09-09-2006 04:24 PM
Copy a record RHall Programming 2 02-23-2006 04:40 AM


All times are GMT -8. The time now is 02:52 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.