Hello All,
I have a text box where the user enters an invoice number and I am checking table "dbo_Tbl_AP" to make sure the invoice doesn't already exist. If the Invoice exists I want to show the label "lbl_Add_Duplicate_Invoice" and force the focus back to the text box "txtADD_Invoice". When I run the code below it shows the label when there is a duplicate but it's allowing the user to move the focus to another control.
I have a text box where the user enters an invoice number and I am checking table "dbo_Tbl_AP" to make sure the invoice doesn't already exist. If the Invoice exists I want to show the label "lbl_Add_Duplicate_Invoice" and force the focus back to the text box "txtADD_Invoice". When I run the code below it shows the label when there is a duplicate but it's allowing the user to move the focus to another control.
Code:
Private Sub txtADD_Invoice_LostFocus()
Dim strDupInvoice As Variant
strDupInvoice = Nz(DLookup("[INVOICE NUMBER]", "dbo_Tbl_AP", "[INVOICE NUMBER] = " & Nz(Forms![Frm_Add_Additional_Invoices]![txtADD_Invoice], 0)), 0)
If strDupInvoice <> 0 Then
lbl_Add_Duplicate_Invoice.Visible = True
Me.txtADD_Invoice.SetFocus
Else
If strDupInvoice = 0 Then
lbl_Add_Duplicate_Invoice.Visible = False
End If
End If
end sub