Dlookup 3 criteria

Rhino999

Registered User.
Local time
Today, 12:00
Joined
Feb 8, 2010
Messages
62
Let me thank you in advance for you help.

I have a ComboBox that shows Detail records. When one record is selected, it is loaded to the PODetail Table.
I want to prevent a duplicate selection of a ComboBox record.
I’m trying to use a Dlookup in the AfterUpdate Event of the ComboBox in the Control Source PODetailItem to see if the selected Data is already in the Table. If so, I’ll Undo the selection and send the user a message that the record is already been used.
The fields I’m looking to use for the Dlookup on the Table are ‘PODetailItem’, ‘POID’ and ‘POdetailJobID’.
PODetailItem is (Text), POID is (Number), PODetailJobID is (Number)
The User recognizes what they want to select off the ComboBox by ‘PODetailItem’, which is unique Data.

I have tried every combination of Dlookup syntax that I could think of, to get it to work, but I not been able to do it. If someone can tell me where I’m going wrong, I would very grateful.
I can get it to work using 1 criteria, but once I add an And Condition, it will not work.

This is just one variation that I tried. I have run a lot of them and I hope this is the one that does return False although I don't think it matters because none of them worked.

Dim CheckForItem As String
Dim CheckForPOID As Integer
Dim CheckForJobID As Integer
Dim stLinkCriteria As String

stLinkCriteria = "[PODetailItem] = " & "'" & CheckForItem & "' And [PODetailJobID] " = "& [CheckForJobID]& " And [POID] = " & [CheckForPOID] & " '"

When I run this version it returns stLinkCriteria, with a value of False.
I have run it other ways and get the correct values, but I get a Mismatch as well as other errors when going through the Dlookup code below.

If Me.PODetailItemID.Column(1) = DLookup("[PODetailItem]", "tblPODetail", stLinkCriteria) Then
MsgBox " Etc”
Me.Undo
End If

Again, thank you for your help!
 
A couple of misplace quotes. Try

stLinkCriteria = "[PODetailItem] = '" & CheckForItem & "' And [PODetailJobID] = " & [CheckForJobID] & " And [POID] = " & [CheckForPOID]
 
pbaldy, thank you for responding.

I ran your solution an it does not get an error or Mismatch. I worked correctly! Thank you!

Now that it has finally worked, I'll be able to check out the rest of my code.

Thanks so much!
 
Last edited:
Have you populated the variables, or are you expecting it to use form controls of the same name?
 
pbaldy, your so right as usual!

After replying back to you, I when through the code and I saw exactly that I had not yet loaded the values to stLinkCriteria.

Thanks again so much.
You are of immense help to the VBA, and Access Community!
 
I'm always right! Except when I'm wrong. :p

Glad we got it working for you.
 

Users who are viewing this thread

Back
Top Bottom