Dlookup - Multiple Items

pjmatelli

Board Regular
Joined
Oct 13, 2005
Messages
206
Hi All,
I am using the following code to find out if an item has already been entered on a PO. It works, but for ALL POs. This code will only allow me to order any item once - no matter what the PO # is. I need it to check for the Item # and PO# combination. Also, I can't seem to find the code to delete the current record. Any advice??? Thanks so much!

Private Sub Item___BeforeUpdate(Cancel As Integer)
If Me.[Item #] = DLookup("[Item #]", "[tblPOTransDetail]", "[Item #] = form![Item #]") _
And Me.[PO#] = DLookup("[PO#]", "[tblPOTransDetail]", "[PO#] = form![PO#]") Then
MsgBox "You have already ordered that item on this PO!", , "Repeated Item!"
DoCmd.CancelEvent

'***Delete Current Record***

End If
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

pjmatelli

Board Regular
Joined
Oct 13, 2005
Messages
206
I figured out my answer. I created a 'joined data' field and have my dlookup check that field and it works perfectly!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,878
Messages
5,834,200
Members
430,263
Latest member
abz54

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top