search to see if specific record is in table

K

Ken Ivins

I have a button to post billing of a new customer to a table but want keep
the user from accidentally posting the same bill (same billing period)
twice.

There will be other customers with the same billing period date and each
customer may have a bill with a different bill date.

So I want to look up on the billing table for the customers ID
(biCustomerId) (matched from the frmCustomer - the txbcuID field) and then
look to see if it has the same billing period date (biDate) that matches the
field txbDate from the frmBilling.

If it finds a record then a message box, if it does not find a record then
it proceeds (this is the easy part).

Do I use Find, DLookup or another method to find if this record exists? I
know how to do a DLookup for one field, but is there a way to do it for two
fields or do I need a combination of things?

Thanks for your help.
Ken
 
A

Allen Browne

Yes, DLookup() can match more than one field:

strWhere = "(biCustomerId = " & me.txtcuID & _
") AND (biDate = " & Format(Me.txtbDate, "\#mm\/dd\/yyyy\#") & ")"
If Not IsNull(DLookup("biCustomerId", "MyTable", strWhere)) Then ...
 

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