Private Sub InvoiceID_BeforeUpate(Cancel As Integer)
Dim strWhere As String
Dim strMsg As String
Dim varResult As Variant
With Me.[InvoiceID]
If Me.NewRecord And Not IsNull(.Value)
strWhere = "[InvoiceID] = " & .Value
varResult = DLookup("InvoiceID", "tblInvoice", strWhere)
If Not IsNull(varResult) Then
Cancel = True
strMsg = "That invoice number already exists." & vbCrLf & _
"Enter a different number, or press "<Esc> to undo."
MsgBox strMsg, vbExclamation, "Duplicate"
End If
End If
End With
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"aw" <(E-Mail Removed)> wrote in message
news:AED2419D-70A6-451F-8E11-(E-Mail Removed)...
> I have a FORM to input NEW invoice information.
>
> How can I write code for prompt user of duplicate invoice number being
> inputted (under the form) when user leave this field IMMEDIATELY
>
> (rather than my existing one do this when all information already input
> and
> prompt you at the time of saving)
>
> --
> aw