Dlookup multi criteria (1 Viewer)

DaManJC

New member
Local time
Today, 09:35
Joined
Sep 23, 2020
Messages
4
Access World,

I'm currently in a bind with Dlookup feature in MS access. I have tried in many different formats mentioned in various forums and websites but i just have not been able to get the "AND" function to add second criteria. Any help is very much appreciated.

=DLookUp("[tbl_BackLogWithLinkedWO]![WORK_ID]","[tbl_BackLogWithLinkedWO]","[tbl_BackLogWithLinkedWO]![SO No]= '" & [SO No] & "' and [tbl_BackLogWithLinkedWO]![LINE_NO]= '" & [LINE_NO] & "'")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:35
Joined
Oct 29, 2018
Messages
21,457
Hi. Welcome to AWF!

That looks okay to me. What exactly were you trying to accomplish with it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:35
Joined
Sep 21, 2011
Messages
14,238
Put the criteria into a string variable and Debug.Print that variable.
That will show you your errors, also you can post the result here within code tags if you need more help.
 

namliam

The Mailman - AWF VIP
Local time
Today, 16:35
Joined
Aug 11, 2003
Messages
11,695
Three likely problems... well two actually
"[tbl_BackLogWithLinkedWO]![WORK_ID]" > "[WORK_ID]" , no need to prefix the table name... neither so in the where cluase.

And NO suggest a number, which doesnt require quotes in the string

DLookups are usually a bad habit though, consider your considerations about using it at all.
 

Minty

AWF VIP
Local time
Today, 15:35
Joined
Jul 26, 2013
Messages
10,368
You don't need all those table references and square brackets - I tend to leave them on the criteria fields just to make it obvious they are field criteria.

=DLookUp("WORK_ID","tbl_BackLogWithLinkedWO","[SO No]= '" & [SO No] & "' and [LINE_NO]= '" & [LINE_NO] & "'")

So what error are you getting, and is SO_No a text field or number and is Line_No a text field or a number?
 

DaManJC

New member
Local time
Today, 09:35
Joined
Sep 23, 2020
Messages
4
Hi. Welcome to AWF!

That looks okay to me. What exactly were you trying to accomplish with it?

I'm trying to get the actual Work_ID linked to the SO No and Line_No,
 

Attachments

  • table i need data from.jpg
    table i need data from.jpg
    109.3 KB · Views: 88
  • query form is bound to.jpg
    query form is bound to.jpg
    287.9 KB · Views: 89

theDBguy

I’m here to help
Staff member
Local time
Today, 07:35
Joined
Oct 29, 2018
Messages
21,457
I'm trying to get the actual Work_ID linked to the SO No and Line_No,
Hi. Looks like [SO NO] is Text but [LINE_NO] is a Number. Were you getting a #Type! as a result?
 

Minty

AWF VIP
Local time
Today, 15:35
Joined
Jul 26, 2013
Messages
10,368
You are comparing them both as text, but Line_No is a number so don't add the ' ' around it;

=DLookUp("WORK_ID","tbl_BackLogWithLinkedWO","[SO No]= '" & [SO No] & "' and [LINE_NO]= " & [LINE_NO] )
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:35
Joined
Oct 29, 2018
Messages
21,457
#error is what I'm getting once I add the second criteria
Okay, it's not what I was expecting, but let's try it anyway. What do you get with this?
Code:
 =DLookUp("[WORK_ID]","tbl_BackLogWithLinkedWO","[SO No]= '" & [SO No] & "' AND [LINE_NO]= " & [LINE_NO])
 

DaManJC

New member
Local time
Today, 09:35
Joined
Sep 23, 2020
Messages
4
It worked!. I really appreciate your input, I've been on this on and off for 2 days. thank you so much along with everyone else that replied.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:35
Joined
Oct 29, 2018
Messages
21,457
It worked!. I really appreciate your input, I've been on this on and off for 2 days. thank you so much along with everyone else that replied.
Hi. Glad we could assist. Good luck with your project.
 

Users who are viewing this thread

Top Bottom