Solved

how to dlookup up for multiple criteria

Posted on 2013-06-29
11
424 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 40

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
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

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
 
LVL 40

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 40

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File.Search issue 8 33
ADODB problem 20 38
IIF in access query 19 25
How to execute a SQL Server Stored Procedure from an Access front-end? 15 37
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

828 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