The code that assigns the value to stLinkCriteria is supposed to be all
on
one line, not the 3 lines that appear due to word-wrap.
Not sure about why the initial line would cause an error. See whether
fixing
the other problem fixes it.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Sorry I am still with errors...I am receiving 'compile error/syntax
error'
..this is how it looks: (But Private Sub txtLastName...is highlighted
in
yellow and stLinkCriteria is all in red). I am really a novice as you
can
tell, but just seems like I am almost there...thank you for your
continued
help.
Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strLastName.Value
stLinkCriteria = "[strLastName]= '" & SID & "' And [strFirstName]= '"
&
strFirstName & "' And [dtmDOB] = " &
Format(nz(dtmDOB,Date()),"\#yyyy-mm-dd\#")
If DCount("strLastName", "tblPatientInformation", stLinkCriteria) > 0
Then
Me.Undo
MsgBox "Warning Possible Duplicate Record" & vbCr & vbCr & "You will
now
be
taken to the record.", vbInformation, "Duplicate Information"
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
--
Kbelo
:
Extra " before And [StrFirstName]
stLinkCriteria = "[strLastName]= '" & SID & "' And [strFirstName]= '"
&
strFirstName & "' And [dtmDOB] = " &
Format(nz(dtmDOB,Date()),"\#yyyy-mm-dd\#")
Note That I also changed the Date Field's Format to one that is valid
regardless of Regional Settings.
Access only recognizes US Format: mm/dd/yyyy & Military Format:
yyyy-mm-dd
Pieter
Thank you for helping...but I am now receiving a syntax error and I
just
don't know how to fix it. Here is the whole code so far:
Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strLastName.Value
stLinkCriteria = "[strLastName]= '" & SID & "' " And
"[strFirstName]=
'"
&
strFirstName & "' And [dtmDOB] = #" & nz(dtmDOB,Date()) & "# "
If DCount("strLastName", "tblPatientInformation", stLinkCriteria) >
0
Then
Me.Undo
MsgBox "Warning Possible Duplicate Record" & vbCr & vbCr & "You will
now
be
taken to the record.", vbInformation, "Duplicate Information"
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
Can you see where I am going wrong? Thanks so much again.
--
Kbelo
:
you have to many spaces in the criteria & you can solve the null
date
issue
stLinkCriteria = "[strLastName]= '" & SID & "' " And
"[strFirstName]=
'"
&
strFirstName & "' And [dtmDOB] = #" & nz(dtmDOB,Date()) & "# "
hth
Pieter
Thank you for your response...and I adjusted the code to the
following:
stLinkCriteria = "[strLastName]= ' " & SID & " ' " And
"[strFirstName]=
'
"
& strFirstName & " ' And [dtmDOB] = #" & dtmDOB & " # ; "
But I am receiving Run Time Error 13 (type mismatch). I am
wondering
(guessing?) that I am not handling Null values. The LastName,
FirstName
and
DOB are the first three fields on the form. If I have the Before
Update
on
the LastName field, then the other two are currently blank.
Should I
have
the
Before Update on the third field (DOB field) only?
Sorry that I am so lost....thanks again for your help.
--
Kbelo
:
On Oct 16, 5:45 pm, Kathy <
[email protected]>
wrote:
I have been struggling with this code and trying to learn from
other
threads.
I am trying to check three fields on a form for
duplicates...specifically
LastName, FirstName and DOB (date of birth) and if there are
any
records
already in the table that match ALL three, then a warning
message
is
given
and you are taken to that record. So far I have the code
working
for
one
field, but I get problems when I try to add other fields. I am
a
novice
and
probably 'over my head', but I seem so close..any suggestions
or
help
is
greatly appreciated.
Here is the working code for one field.
Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.strLastName.Value
stLinkCriteria = "[strLastName]=" & "'" & SID & "'"
Should be something like this:
stLinkCriteria = "[strLastName]= ' " & SID & " ' AND
[strFirstName]= ' " & sFirstName & " ' AND [strBirthDate] = #" &
sBirthDate & " # ; "
If DCount("strLastName", "tblPatientInformation",
stLinkCriteria)
0
Then
Me.Undo
MsgBox "Warning Possible Duplicate Record" & vbCr & vbCr &
"You
will
now be
taken to the record.", vbInformation, "Duplicate Information"
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub
Many thanks!