Michelle Michy
Member
- Local time
- Today, 16:11
- Joined
- May 11, 2023
- Messages
- 46
Hi all.
I have the following code
It helps prevent duplicate but does not take me to existing record. Instead I get the following error
Run-time error '3420'
Object invalid or no longer set.
I can't figure out where I did wrong. Please kindly help me.
I have the following code
Code:
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
It helps prevent duplicate but does not take me to existing record. Instead I get the following error
Run-time error '3420'
Object invalid or no longer set.
I can't figure out where I did wrong. Please kindly help me.