K
KateB
I have a database for patient details with one table [colp_patients]. It has
a unique ID field, and an NHSNo field (which is a text field - it needs
spaces), which is also unique to the patient. I was led to believe the same
patient could be entered many times, but have since been told that one
patient should only have one record. Therefore, each time the inputter
enters the NHS number on the form I would like it to check for previous
entries and take the inputter to that entry.
I found some code on another web site (see below) which I tried to amend but
without success. If I delete the 'str' before NHSNo it fails each time. If
I leave it in, the before update event procedure isn't stored in the
properties, or it just doesn't do anything! I hope its something really
simple but being unfamiliar with code etc can't solve it. Can anyone give me
"idiot guide" help?!
Private Sub strNHSNo_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strNHSNo.Value
stLinkCriteria = "[strNHSNo]=" & "'" & SID & " ' "
If DCount("strNHSNo", "tblColp_Patients", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
MsgBox "Warning NHS Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.",
vbInformation _
, "Duplicate Information"
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
a unique ID field, and an NHSNo field (which is a text field - it needs
spaces), which is also unique to the patient. I was led to believe the same
patient could be entered many times, but have since been told that one
patient should only have one record. Therefore, each time the inputter
enters the NHS number on the form I would like it to check for previous
entries and take the inputter to that entry.
I found some code on another web site (see below) which I tried to amend but
without success. If I delete the 'str' before NHSNo it fails each time. If
I leave it in, the before update event procedure isn't stored in the
properties, or it just doesn't do anything! I hope its something really
simple but being unfamiliar with code etc can't solve it. Can anyone give me
"idiot guide" help?!
Private Sub strNHSNo_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strNHSNo.Value
stLinkCriteria = "[strNHSNo]=" & "'" & SID & " ' "
If DCount("strNHSNo", "tblColp_Patients", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
MsgBox "Warning NHS Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.",
vbInformation _
, "Duplicate Information"
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub