Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a form showing existing duplicates

Status
Not open for further replies.

dryc

Technical User
Mar 5, 2002
5
US
Could someone tell me how to setup a query that will look for duplicate records in a field after update and only have a form with the duplicates popup if there are duplicates?
 
Sure,

In the field you want to check on, in it's After Update event you could use code such as:

Private Sub txtMyField_AfterUpdate()
' Go to Tools > References and insure that
' there is a reference to
' Microsoft DOA x.x Object Library
' where x.x is the latest version you have

Dim rst As DAO.Recordset
Dim varBookmark As Variant

If Not IsNull(txtMyField) Then
Set rst = Me.RecordsetClone

'Find the record that matches the control
With rst
varBookmark = Me.Bookmark
.FindFirst "[CustomerName] = " & chr(34) & txtMyField & chr(34)

If not .NoMatch Then
DoCmd.OpenForm "YourFormName", , , "CustomerName = " & Chr(34) & txtMyField & Chr(34)
End If

.Close
End With
Set rst = Nothing
End If

End Sub

In the form that you want opened, set the recordsource so that you display the info you want to show when there are duplicates. John Ruff - The Eternal Optimist :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top