T
ThomasK via AccessMonster.com
I found this code on this forum. Thanks John Vinson!!!, it works great. But
what I was wondering is what if one of the fields was a number field and not
a text field. What Im trying to do is look for identical addresses.
Thanks for the help.
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim rs As DAO.Recordset
Dim iAns as Integer
Set rs = Me.RecordsetClone ' open the Form's recordset
rs.FindFirst "[LastName] = " & Chr(34) & Me!txtLastname & Chr(34) _
& " AND [FirstName] = " & Chr(34) & Me!txtFirstname & Chr(34)
' Chr(34) is the " character to delimit text strings
If Not rs.NoMatch Then ' Was there a match found?
iAns = Msgbox("This name is already in the database." _
& "Do you want to add it anyway?" _
& "Click Yes to do so, No to erase it and reenter, " _
& "Cancel to cancel this add and jump to the found name:", _
vbYesNoCancel)
Select Case iAns
Case vbYes
Cancel = False
Case vbNo
Cancel = True
Me!txtFirstName.Undo 'erase the entries
Me!txtLastName.Undo
Me!txtFirstName.SetFocus
Case vbCancel
Me.Undo ' erase the whole form
Me.Bookmark = rs.Bookmark ' jump to found record
End Select
End If
End Sub
what I was wondering is what if one of the fields was a number field and not
a text field. What Im trying to do is look for identical addresses.
Thanks for the help.
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim rs As DAO.Recordset
Dim iAns as Integer
Set rs = Me.RecordsetClone ' open the Form's recordset
rs.FindFirst "[LastName] = " & Chr(34) & Me!txtLastname & Chr(34) _
& " AND [FirstName] = " & Chr(34) & Me!txtFirstname & Chr(34)
' Chr(34) is the " character to delimit text strings
If Not rs.NoMatch Then ' Was there a match found?
iAns = Msgbox("This name is already in the database." _
& "Do you want to add it anyway?" _
& "Click Yes to do so, No to erase it and reenter, " _
& "Cancel to cancel this add and jump to the found name:", _
vbYesNoCancel)
Select Case iAns
Case vbYes
Cancel = False
Case vbNo
Cancel = True
Me!txtFirstName.Undo 'erase the entries
Me!txtLastName.Undo
Me!txtFirstName.SetFocus
Case vbCancel
Me.Undo ' erase the whole form
Me.Bookmark = rs.Bookmark ' jump to found record
End Select
End If
End Sub