Solved

DLOOKUP is not returning a value - ms/access 2013

Posted on 2014-12-28
8
284 Views
Last Modified: 2014-12-29
I am running a query that needs to compute a value based on one external table. The  Table, named "__parametrosAAP", contains 3 fields for this purpose. A minimum value, a maximum value and a key value, named, respectively, [PopAlvoInf], [PopAlvoSup] and [ClasseAAP].
Depending on a value on the query, [PopPNUD] I need to select a specific record from "__parametrosAAP" and put it in the [ClassePNUD] column.

Thus I have the following query formula:

ClassePNUD: DLookUp("[ClasseAAP]";"__parametrosAAP";[PopPNUD]<=" [__parametrosAAP]![PopAlvoSup]  " And [PopPNUD]>="[__parametrosAAP]![PopAlvoInf]")

But, no matter how, it is always returning null values, in spite the table being correctly filled.

The query is named "sustenta 02 prep" and I am sending the database, just in case.

Can anyone help?

joao
sireshDB-11.accdb
0
Comment
Question by:jirdeaid
  • 4
  • 4
8 Comments
 

Author Comment

by:jirdeaid
ID: 40520487
A Post scriptum -

I did replace, i the formula, the [PopPNUD] by a number (1050) and got the error "data type mismatch", a bit stupid as all values are number. The text was like:

ClassePNUD2: DLookUp("[ClasseAAP]";"__parametrosAAP";1050<=" [__parametrosAAP]![PopAlvoSup]  " And 1050>="[__parametrosAAP]![PopAlvoInf]")
0
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 40520505
Try

ClassePNUD: DLookUp("[ClasseAAP]";"__parametrosAAP";"([PopPNUD]<= [PopAlvoSup]) And ([PopPNUD]>=[PopAlvoInf])")
0
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 40520512
I checked your database and you do not have any field called "[PopPNUD]".

If you want to use the 1050, please do the following:

ClassePNUD2: DLookUp("[ClasseAAP]";"__parametrosAAP";"(1050<= [__parametrosAAP]![PopAlvoSup])  And (1050>=[__parametrosAAP]![PopAlvoInf])")

The problem is where you put the "

Abracos
0
 

Author Comment

by:jirdeaid
ID: 40520522
Hi fabricio -

As I am scratching my head, it suddenly almost  started to work. I don't want to use the 1050 - that was only a try to check what was wrong.
The table "__parametrosAAP" contains the min and max values. The query "sustenta 02 prep" contains the field [PopPNUD]. Pleas check below.

screenshot

When I run the query it now selects one of the 6 options. But always the same option (sigh) -> "Tipo I" so it looks that something is really wrong with the dlookup itself.

Actually, I did another try, now on the last column, replacing the [PopPNUD] field by the fized value "3500". This should yield the result "Tipo IV" and not "Tipo I" as it is!!!

screenshot 2
I am uploading the database again so you can check.

joao
sireshDB-11.accdb
0
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.

 
LVL 8

Accepted Solution

by:
fabriciofonseca earned 500 total points
ID: 40520562
Ok... I believe I found the solution...

try the following:

ClassePNUD2: DLookUp("[ClasseAAP]","__parametrosAAP","((Int(" & [CenarioConsumo].[Proj_2014] & "*" & [_Sustenta 01 Prep].[TxAcum] & "/10+0.5)*10)<= [PopAlvoSup])  And ((Int(" & [CenarioConsumo].[Proj_2014] & "*" & [_Sustenta 01 Prep].[TxAcum] & "/10+0.5)*10)>=[PopAlvoInf])")

Now please sit before you read the following lines:

In you table "__parametrosAAP" the fields "PopAlvoInf" and "PopAlvoSup" have conflict information. Check it:

PopAlvoInf      PopAlvoSup
0      1000
1001      1500
2001      2000
3001      3000
3001      5000
5001      100000

I understand "inf" means the minimum number and "Sup" means the maximum number, therefore you cannot have 2001 as minimum and 2000 as maximum??? Also you do not have any range covering from 1500 to 2000. Please check all the ranges ans make sure they cover your needs.

Abracos
0
 

Author Closing Comment

by:jirdeaid
ID: 40520589
Gee!!!!! It works perfectly! And thanks for the table correction!!!!!!

From what I understood, what you did was to always make the original table/query EXPLICIT. Is it?

T H A N K S     A     L O T !!!!
0
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 40521899
I did 2 important changes:

1-) Changed the calculated field name [PopPNUD] by its formula in the [ClassePNUD2]. You cannot use a calculated field name in a different field in the same query you are creating the original calculated field.

2-) The DLookup works with string parameters, therefore I had to concatenate a string in the "where" clausure. If you look in details you will realize this part is concatenated by &. For example the "Int(" & [CenarioConsumo].[Proj_2] & ")" will concatenate the string "Int(" with the value in [CenarioConsumo].[Proj_2] with the string ")" creating something like "int(1234)"

I hope it clarifies how the solution was reached.

Abracos
0
 

Author Comment

by:jirdeaid
ID: 40522328
and re-THANKS!!!!!!!
abraços tb (de Portugal)
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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

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