I have a data entry form that lists the details of building sales. I know a building can sell more than once so I need to allow duplicate addresses. However, occasionally the same sale will get entered more than once. I have code that checks if the address is a duplicate and takes the user to the existing record to verify the information and this works fine. But as I add more sales into the database, the possibility of more than one sale for a particular property being entered. I now find the need to not only check for duplicate sales but there is more than one to compare to. I'm not sure if this is possible or if I should add another criteria such as sales date to find an existing sale. Make sense? the following is the code I have thus far and works for one record:
Code:
Private Sub txtAddress_BeforeUpdate(Cancel As Integer)
Dim strMsg1, strMsg2, strMsg3, strMsg4, strMsg5 As String
Dim strFind As Variant
Dim rs As DAO.Recordset
Dim strCriteria, strAddress As String
strMsg1 = "This address already exists."
strMsg2 = "Click OK to be taken to the record to verify." & Chr$(13) & Chr$(10)
strMsg3 = "If the record you are trying to enter already exists, do nothing."
strMsg4 = "Otherwise add a new record and select no to continue."
strMsg5 = strMsg1 & Chr$(13) & Chr$(10) & strMsg2 & Chr$(13) & Chr$(10) & strMsg3 & Chr$(13) & Chr$(10) & strMsg4
Set rs = Me.RecordsetClone
strAddress = Me.[txtAddress].Value
strCriteria = "[Location_Address]=" & "'" & strAddress & "'"
If DCount("[Location_Address]", "tblCom_Buildings", strCriteria) > 0 Then
If MsgBox(strMsg5, vbInformation + vbYesNo, "Duplicate Address") = vbYes Then
Me.Undo
rs.FindFirst strCriteria
Me.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
Else
Exit Sub
End If
End If
End Sub
Comment