Finding identical addresses

  • Thread starter ThomasK via AccessMonster.com
  • Start date
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
 
P

Piet Linden

I assume getting rid of these

& Chr(34) &
& Chr(34)

Lemme know.

ThomasK via AccessMonster.com said:
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

Correct. If you are comparing numbers, you don't need delimiters.
 
T

ThomasK via AccessMonster.com

You are both right, I didn't need them. I took them out and it worked great.
Thanks a lot for the help. This is a great fourm.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top