2 unique Values

A

Anthony Viscomi

I have an Invoice frm (& tbl) and I want to allow the user to enter an
invoice # and select a vendor from a cboVendor. But if that Vendor and
Invoice# combination already exist; then display msg.

Simply put, how do I prevent entering a duplicate invoice from th same
vendor?

Thanks in advance!
Anthony
 
L

Larry Linson

How are Invoice #s determined? You could create the Invoice # from code to
assure that it did not conflict with an existing one.

Larry Linson
Microsoft Access MVP
 
J

John Vinson

I have an Invoice frm (& tbl) and I want to allow the user to enter an
invoice # and select a vendor from a cboVendor. But if that Vendor and
Invoice# combination already exist; then display msg.

You could create a unique Index on the combination of the two fields
to absolutely prevent addition of such a record.

If you just want to check, use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("InvoiceNo", "Invoices", "InvoiceNo = " _
& Me.txtInvoiceNo & " AND VendorID = " & Me.cboVendor) Then
MsgBox "This vendor has already been entered for this invoice"
Cancel = True
End If
End Sub

John W. Vinson[MVP]
 
A

Anthony Viscomi

Thanks all!
John Vinson said:
You could create a unique Index on the combination of the two fields
to absolutely prevent addition of such a record.

If you just want to check, use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("InvoiceNo", "Invoices", "InvoiceNo = " _
& Me.txtInvoiceNo & " AND VendorID = " & Me.cboVendor) Then
MsgBox "This vendor has already been entered for this invoice"
Cancel = True
End If
End Sub

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top