If the user is entering an address into a *bound* form, use the BeforeUpdate
event procedure of the *form* (not control) to check if the address already
exists.
This example will need modifying to match your field names:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String
If (Me.Address = Me.Address.OldValue) AND (Me.State = Me.State.OldValue)
AND (Me.Zip = Me.Zip.OldValue) Then
'do nothing
Else
strWhere = "([Address] = """ & Me.Address & """) AND ([State] = """
Me.State & """) AND ([Zip] = """ & Me.Zip & """)"
varResult = DLookup("AddressID", "tblAddress", strWhere)
If Not IsNull(varResult) Then
strMsg = "Duplicate of address " & varResult & vbCrLf & vbCrLf &
"CONTINUE ANYWAY?"
If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Warning") <>
vbYes Then
Cancel = True
Me.Undo
End If
End If
End If
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
headly said:
When a user enters a new address, I'd like to check to see if it already
exists before updating the table; So, I select the form, show the
properties,
and go to the event - before update; What macro instructions or vba would
i
use to search for the typed address value before committing the update?