Solved

how to dlookup up for multiple criteria

Posted on 2013-06-29
11
419 Views
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
AND
CategoryDescription = 2 AND CategoryAcronym = ACT
AND
CategoryDescription = 3 AND CategoryAcronym = E

to get CodeID = 1 as per the below image? thanks guys!!
dlookup
0
Comment
Question by:developingprogrammer
11 Comments
 
LVL 77

Expert Comment

by:peter57r
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?
0
 

Author Comment

by:developingprogrammer
ID: 39286618
all 3 pairs sir. = )
0
 
LVL 39

Expert Comment

by:als315
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
0
 

Author Comment

by:developingprogrammer
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!! = ))
DMS-Cerebro---SSB-Recon.mdb
0
 

Author Comment

by:developingprogrammer
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)
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 39286736
You can concatenate text strings with mattewspatrick's function:
A_2380
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).
DMS-Cerebro---SSB-Recon.mdb
0
 

Author Comment

by:developingprogrammer
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!!!! = ))
0
 
LVL 39

Assisted Solution

by:als315
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:
http://office.microsoft.com/en-us/access-help/set-the-field-size-HA010274716.aspx#BM2
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)
DMS-Cerebro---SSB-Recon.mdb
0
 

Author Closing Comment

by:developingprogrammer
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!! = ))
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39289942
Alexey,

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

developingprogrammer: glad my code was useful to you!

Cheers,

Patrick
0
 

Author Comment

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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

15 Experts available now in Live!

Get 1:1 Help Now