Stopping Duplicate Value Entries

malsla

New member
Local time
Today, 05:22
Joined
Oct 17, 2006
Messages
4
Hi,
Sorry if this is a bit wordy...my first time...here goes....

I'm building a booking request database, where users at some stage enter the date for which they wish to book.
What I want is that if they enter a date that already exists in that field then they are told this and are taken to that record.
However, what is happening is that whatever date I enter it says that it already exists and when it attempts to locate the record i get an Error 3021 message and the VB highlights the "Me.Bookmark = rsc.Bookmark" line of my code for debugging....

CAN ANYONE HELP??? TRYING TO MEET A DEADLINE...

my code is as follows: -
(before update)
Code:
Private Sub Date_Required_BeforeUpdate(Cancel As Integer)


Dim D As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

D = Me.Date_Required.Value
stLinkCriteria = "[Date_Required]=" & "'" & D & "'"

    'Check StudentDetails table for duplicate StudentNumber
    If DCount("Date_Required", "Bookings", stLinkCriteria) > 0 Then
        'Undo duplicate entry
        Me.Undo
        'Message box warning of duplication
        MsgBox "Warning! " _
        & D & " 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
 
stLinkCriteria = "[Date_Required] =" & chr(35) & format(D,"mm/dd/yy") & chr(35)
 

Users who are viewing this thread

Back
Top Bottom