how to dlookup up for multiple criteria

Posted on 2013-06-29
Last Modified: 2013-07-01
hi guys, i want to write a dlookup line or whichever other method i'm ok also - just how do i look up with the criteria that:

CategoryDescription = 1 AND CategoryAcronym = H
CategoryDescription = 2 AND CategoryAcronym = ACT
CategoryDescription = 3 AND CategoryAcronym = E

to get CodeID = 1 as per the below image? thanks guys!!
Question by:developingprogrammer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 77

Expert Comment

ID: 39286599
What are you trying to look up?

Do you mean that all three pairs of values must exist  to return a value or do you mean that one (or more) of the three pairs must exist?

Author Comment

ID: 39286618
all 3 pairs sir. = )
LVL 40

Expert Comment

ID: 39286630
Dlookup can return you only one record. You like to analyze set of records, so you should make some concatenation of your data before you will be able get ID from dlookup.
In your case you can sum numeric fields as bit 2^CategoryDescription and concatenate sorted text fileds and get following result:
1   14       ACT-E-H
2   14       ACT-E-R

Now you can make dlookup
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


Author Comment

ID: 39286668
what would be the best way to make a concatenated field?

Table --> Select Query --> Dlookup from query?

sorry to trouble als315 but do you think you could show me how you'd do it using this database i just attached here?

must i have fixed columns for the concatenation or can i do it in a way such that it kinda concatenates like a crosstab query? a crosstab query with the ability to have more than 1 column header cause currently that's the crosstab query's limitation right?

thanks als315!! = ))

Author Comment

ID: 39286708
Oh what I meant by the fixed column headers thing is - can the concatenation be done in a way that can dynamically increase should I add more categories? E.g. Now I have cat 1, cat 2 and cat 3. What if I add one more cat 4 just like in the DB I submitted - H-ACT-E-Z versus C-ACT-E (4 categories vs 3 categories)
LVL 40

Accepted Solution

als315 earned 500 total points
ID: 39286736
You can concatenate text strings with mattewspatrick's function:
or you can add numeric field to your table (perfAcronymDefinition) with degrees of 2 and simply sum these values.
With simple function (see module1, comparebit function) you can make bit compare of this sum.
Look at query1
In your sample bit sum of CategoryDescription (CD field) for Id 1 will be14 (1-2-3 = 2+4+8) and for ID 2 - 30 (1-2-3-4 = 2+4+8+16). Both contain bits 2,4,8, so result of compare will be true for both cases.
Second parameter (CB field) will be 26 (ACT-E-H = 2+8+16) for ID 1 and 15 for ID 2 (ACT-C-E-Z = 2+4+8+1).

Author Comment

ID: 39287717
whao als315, that is some seriously amazing logic!!!!

i spent some time to understand - got 3 questions.

1) what if i have 10,000 AcronymDefinition rows? then the CategoryBit of 1,2,4,8,16,32 will very very quickly run out right? please correct my maths if its wrong, but using a 4 byte unsigned long, i would only have 8 + 8 + 8 + 8 = 32 AcronymDefintion rows right?

2) long integer is a signed number. if i really do have only 32 AcronymDefinitions, then i will have to key in negative numbers for anything above 32k right?

3) so assuming i stay within the limits of 32 rows, then how i would use the solution you gave me is that i will get an Acronym from the user (say they key in ACT), then i'll use dlookup to get its CategoryBit, and then repeat the steps for H, E and once i've gotten the 3 CategoryBits for the Acronyms then i'll sum them up and use a dlookup from the query1 select query you gave me it that correct?

thanks so much once again als315 for your help!!!! = ))
LVL 40

Assisted Solution

als315 earned 500 total points
ID: 39287814
1. Yes, you need some alternate way for this case. You may use some predefined AcronimDefinition groups. I think it is also possible.
2. Long integer could be from 2,147,483,648 to +2,147,483,647:
really max is 2^30, because CLNG(2^31) will give overflow. You can use HEX text strings or any other text encoding, but logic will not be so simple.
3. look at sample DB (Form1)

Author Closing Comment

ID: 39289790
thanks als315!! i superbly superbly superbly like you solution!! but unfortunately i had too many categories and the UDF you suggested by matthewspatrick was a lot easier so i went by that route. but your solutions always blow me away in amazement. always left wonder how in the world you thought about such a cool idea!! = ))
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39289942

Thanks for recommending my article.  Recommendations from fellow Experts are the highest form of praise :)

developingprogrammer: glad my code was useful to you!



Author Comment

ID: 39289966
= ) thanks for all your help all this while Patrick! = )

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

734 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