Solved

DLookup with multipul criteria

Posted on 2014-01-14
8
218 Views
Last Modified: 2014-01-14
Trying to get this multicriteria dlookup  to work but I keep getting syntax errors..... any assistance is appreciated.

Thank you.

sAccountNo = DLookup("ActNo", "tOutLab", "Lab = " & "'" & Me.OutLab & "'" & " AND " & "'" & "Office = " & "'" & Me.Office & "'")
0
Comment
Question by:thandel
  • 4
  • 2
  • 2
8 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 39781125
Can you advise what data types are the columns tOutLab and Office in your ActNo table?
Can you advise what controls are Me.OutLab and Me.Office (most likely text boxes, but please double check)
0
 

Author Comment

by:thandel
ID: 39781132
Yes the tOutlab is a string, Office is also a string, Me.Outlab and Me.office are combo boxes.
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 total points
ID: 39781138
I find using single quote around text values is easier that endless double quotes, so I'd suggest
sAccountNo = DLookup("ActNo", "tOutLab", "Lab = '" &Me.OutLab & "' AND Office = '" & Me.Office & "'")


Kelvin
0
 

Author Comment

by:thandel
ID: 39781143
Thanks but I'm getting a run time error of "you have cancelled the previous operation"
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 24

Expert Comment

by:chaau
ID: 39781144
Depending on how Combo Boxes are created either first or second will work:
sAccountNo = DLookup("ActNo", "tOutLab", "Lab = '" & Me.OutLab.Text & "' AND Office = '" & Me.Office.Text & "'") 

Open in new window

sAccountNo = DLookup("ActNo", "tOutLab", "Lab = '" & Me.OutLab.Value & "' AND Office = '" & Me.Office.Value & "'") 

Open in new window

Explanation: You can create Combo Boxes on the form that display text for the items, but the values for the items will have different codes. In this case the actual value that the tables need to be compared with need to be tested against "Value" property. Most of the time, however, you need to test against "Text" property
0
 

Author Comment

by:thandel
ID: 39781150
Sorry neither is working... I don't think I need that as the following is working:

sAccountNo = DLookup("ActNo", "tOutLab", "Lab = '" & Me.OutLab & "'")

It just the multi-criteria that I can't figure out.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39781155
Chances are the combo uses an ID and displays the text. Try
sAccountNo = DLookup("ActNo", "tOutLab", "Lab = '" & Me.OutLab.Column1 & "' AND Office = '" & Me.Office.Column1 & "'")
0
 

Author Comment

by:thandel
ID: 39781159
Wait sorry you had it above, I had my table mixed.... sorry about that.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now