I have the following code in the Before Update event on my Demographics form:
Code:
Private Sub mrNum_BeforeUpdate(Cancel As Integer)
'Prevents the user from entering a duplicate medical record number in the Demographics form.
Dim mrn As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
mrn = Me.mrNum.Value
stLinkCriteria = "[mrNum]=" & "'" & mrn & "'"
'Check the Demographics table for duplicate Medical Record Number
If DCount("mrNum", "tblDemographics", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "That medical record number has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to original record
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
When the user enters a new medical record number, the code checks to see if the medical record number already exists in the database. If it does, a message box alerts the user of the duplication and then displays the orignal record.
The code has worked perfectly until today. Today, the highlighted line in the code causes run-time error 3420 "Object invalid or no longer set"
I thought maybe the code had somehow become corrupted. But when I went back and tested the code in several of my back up copies of my database, they ALL result in the same error. So it's not the code. Something must have changed with Access or my computer. I haven't a clue what the problem is.