F
FedBrad
Marshall,
Thanks for the quick reply... below is my code. DAO lib reference is
present, and no filters are applied to the underlying table. In fact, since
I am building from scratch, the underlying table currently only has one
existing record - am entering duplicate HICN into the second record to test
this validation scheme.
BID is mine (instead of SID), the field being evaluated is [HICN], and I
used the older fashioned way to do the message box. Oddly enough, the code
seems to be hanging on the very last line:
'**************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
End Sub
'**********************************************
Duplicate HICN is detected, new record being created gets undone, message
fires fine, but does not redirect to the record containing the duplicated
HICN (i.e., in the same form) - at this point, the only other record in the
table. Anything you can see that is out-to-lunch?
Thanks
Thanks for the quick reply... below is my code. DAO lib reference is
present, and no filters are applied to the underlying table. In fact, since
I am building from scratch, the underlying table currently only has one
existing record - am entering duplicate HICN into the second record to test
this validation scheme.
BID is mine (instead of SID), the field being evaluated is [HICN], and I
used the older fashioned way to do the message box. Oddly enough, the code
seems to be hanging on the very last line:
'**************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim BID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Dim Msg. Style, Title, Reponse
Set rsc = Me.RecordsetClone
BID = Me.HICN.Value
stLinkCriteria = "[HICN]=" & "'" & BID & "'"
rsc.FindFirst stLinkCriteria
'Check for duplicate HICN
If rsc.NoMatch = False ThenEnd If'Undo duplicate entry
Me.Undo
'Message box warning of duplication
Msg = " My msg....."
Style = vbOKOnly + vbInformation
Title = "Duplicate HICN"
Response = Msgbox (Msg, Style, Title)
'Go to original record with the duplicate HICN
Me.Bookmark = rsc.Bookmark << hanging here...
Set rsc = Nothing
End Sub
'**********************************************
Duplicate HICN is detected, new record being created gets undone, message
fires fine, but does not redirect to the record containing the duplicated
HICN (i.e., in the same form) - at this point, the only other record in the
table. Anything you can see that is out-to-lunch?
Thanks
Marshall Barton said:FedBrad said:Found this earlier thread, and it is similar to what I am trying to do
(prevent entry of a duplicate value into a new record as it is being created,
then redirect to the existing record), but just a little different. Am using
Access 2007 and have two questions...
1) Shold this code work in Ac2007? (code below is from your other thread,
realize I would have to substitute my own specific references to
fields/forms).
2) Can it be placed into the 'On Lost Focus' event, so that I catch the
duplicate and stop data entry right then, rather than the form's Before
Update event? (it is the first data entry field on the form...).
I have been away from building applications in Access for a couple of years,
and am new to 2007. Thanks. (and, if you prefer I try to duplicate it
first, before just asking up front... please say so, I can take it
Brad
Mike Painter said:I think I got the code backwards (among other errors.
..NoMatch is true if nothing is found, so
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.Initials.Value
stLinkCriteria = "[Initials]=" & "'" & SID & "'"
rsc.FindFirst stLinkCriteria
'Check Contacts table for duplicate Initials
If there is a match NoMatch is False so we want to pop the message and then
move to the record.
If not we just skip over the rest.
If rsc.NoMatch = False Then
' or Not rsc.NoMatch
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning these Initials " _
& "'" & SID & "'" & " have already been entered." _
& vbCr & vbCr & "You will now been taken to the record." _
& vbCr & vbCr & "Please check to see that you are not
entering a duplicate Contact." _
& vbCr & vbCr & "Return if neccessary to enter a unique
set of Initials.", _
vbInformation, "Duplicate Information"
'Go to record of original Initial
' and the Else should not be here.
'rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
As long as you have a reference to the DAO library, that
code should work.
If you are filtering the form's data records (via any of
several methods), the duplicate record might not be in the
form's recordset. Note that is usually a good idea to
filter the form's records to the minimum number that are
required to do the job, ideally just one record.