B
Benedikt
Hi
I am trying to prevent duplicates being entered in my form and if someone
enters number that is already in the table Projects is should go to that
record.
Do you now if this code works only if the field (strStudentNumber) is
PrimaryKey? Is it possible to use this code without PrimaryKey?
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 & "'"
If DCount("strStudentNumber", "Projects", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Reg Number " & SID & " has already been entered." & vbCr &
vbCr & "", vbInformation, "Duplicate Information"
'Go to record of original Reg Number
rsc.FindNext stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
Many thanks.
Benedikt F.
(e-mail address removed)
I am trying to prevent duplicates being entered in my form and if someone
enters number that is already in the table Projects is should go to that
record.
Do you now if this code works only if the field (strStudentNumber) is
PrimaryKey? Is it possible to use this code without PrimaryKey?
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 & "'"
If DCount("strStudentNumber", "Projects", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Reg Number " & SID & " has already been entered." & vbCr &
vbCr & "", vbInformation, "Duplicate Information"
'Go to record of original Reg Number
rsc.FindNext stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
Many thanks.
Benedikt F.
(e-mail address removed)