Error Checking Question

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

Guest

I'm trying to "read" the contents of a field "AfterUpdate". I want to read
the contents, check to see if that value already exists in the table and give
them an error if it already exists.

I'm looking for the syntax of the "read" and "check" part of the logic.

Cheers,
Leslie
 
I'm trying to "read" the contents of a field "AfterUpdate". I want to read
the contents, check to see if that value already exists in the table and give
them an error if it already exists.

I'm looking for the syntax of the "read" and "check" part of the logic.

Cheers,
Leslie

AfterUpdate is too late: the record has already been stored in the
table, whether it's a duplicate or not! I would suggest using the
Form's BeforeUpdate event, and use DLookUp to see if it's a dup:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If Not IsNull(DLookUp("[fieldname]", "[tablename]", "[fieldname] = " _
& Chr(34) & Me![controlname] & Chr(34)) Then
iAns = MsgBox("Duplicate value! Click OK to try a different one," _
& " Cancel to erase the entire record and try over", vbOKCancel)
Cancel = True
If iAns = vbCancel Then
Me.Undo
Else
Me!controlname.Undo
Me!controlname.SetFocus
End If
End If
End Sub

John W. Vinson[MVP]
 
John,

Thank you again for your help. You gave me the exact syntax, and that is
great. I am working at loading it and I'm sure I'll be able to make it work
exactly as I need.

Thank you!
Leslie
 
Back
Top