VERIFY DUPLICATE DATA BEFORE SAVE

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I looking to check the data in a fiel just after dataentry and before
continue to enter the next data field. In a Form. Im using access 2003 and
2007.
 
Use the BeforeUpdate (if you want to cancel it) or AfterUpdate (if you just
to to notify the user) of the control. Use DLookup() to check for a
duplicate in the table.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant
With Me.City
If IsNull(.Value) Or (.Value = .OldValue) Then
'do nothing
Else
strWhere = "[City] = """ & .Value & """"
varResult = DLookup("ID", "Table1", strWhere)
If Not IsNull(varResult) Then
MsgBox "Duplicate"
'Cancel = True
End If
End If
End With

For help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
Back
Top