Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Dlookup

Experts,
I am attempting to do a Dlookup.  I have a syntax.  I think the issue is somewhere around the "179" part but I dont really know.  

If the Guarantor Description is like "DNB*" then I need to lookup the FacilityAmount in tblBankFacilityAmts then subtract the SUM [Approved Amount In USD Equivalent]

The [Approved Amount In USD Equivalent] is a field in the query.  circled in the pic.

here it is:
Available: iif("[Guarantor Description]" like "DNB*", Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] =" 179 – Sum([Approved Amount In USD Equivalent],0) User generated image
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Try this -


Available: iif([Guarantor Description] like "DNB*",  Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] ="  & 179 – Sum([Approved Amount In USD Equivalent]),0)
Avatar of Norie
Norie

If 179 doesn't change put it inside the quotes.

Assuming that's the criteria for [BankName_Facility] of course.

There's a few other things that aren't quite right, well it's just one really - the "s around [Guarantor Description]

Anyway, try this:


Available: IIf( [Guarantor Description] LIKE "DNB*", Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] =179" – Sum([Approved Amount In USD Equivalent],0)
Or this (with parentheses for grouping):

Available: iif([Guarantor Description] like "DNB*",  Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] ="  & (179 – Sum([Approved Amount In USD Equivalent])),0)
Try this:

Available: IIf([Guarantor Description] Like "DNB*", DLookup("[FacilityAmount]", "tblBankFacilityAmts", "[BankName_Facility] = " & 179 - Sum([Approved Amount In USD Equivalent]), 0))

which does compile in vba code.

mx
Avatar of pdvsa

ASKER

Imnorie:
had a syntax
Available: IIf( [Guarantor Description] LIKE "DNB*", Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] =179" – Sum([Approved Amount In USD Equivalent],0)

Mbizup:
had a syntax (it highlighted the "-" sign

Available: iif([Guarantor Description] like "DNB*",  Dlookup("[FacilityAmount]","tblBankFacilityAmts", "[BankName_Facility] ="  & (179 – Sum([Approved Amount In USD Equivalent])),0)

MX:
no syntax  but it said "contained wrong number of arguments":
Available: IIf([Guarantor Description] Like "DNB*", DLookup("[FacilityAmount]", "tblBankFacilityAmts", "[BankName_Facility] = " & 179 - Sum([Approved Amount In USD Equivalent]), 0))

ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK this:

IIf([Guarantor Description] Like "DNB*", DLookup("[FacilityAmount]", "tblBankFacilityAmts", "[BankName_Facility] = " & 179 - Sum([Approved Amount In USD Equivalent])), 0)

mx
The bits I changed added: closing parenthesis for the DLookup, removed the ,0 from Sum - it only takes one argument/expression.
Avatar of pdvsa

ASKER

Imnorie:  that was the solution.

thank you
pdvsa,  How can that work since the 2nd argument for IIF is missing ... namely  ,0)
What I posted first should also work ... @ http:#a37051100

?
mx,

That Value If False argument is optional if it is used in an SQL statement.

Both you and I had missing and/or misplaced parentheses.
Avatar of pdvsa

ASKER

I adjusted it.  The main pt of it was the minus "-" sign part.   Your answer gave me 0.  It seemed to be the opposite of Imnories.  If I removed the 0 then it did not return any result.
MX

It certainly seemed to work and Access didn't complain about the missing falsepart.

It also works with the falsepart.

IIf([Guarantor Description] Like "DNB*",DLookUp("[FacilityAmount]","tblBankFacilityAmts","[BankName_Facility] =179")-Sum([Approved Amount In USD Equivalent]), 0)
If may be optional, BUT ... not if you really wanted the zero.

And my last post has no missing parens, as it compiles in vba just fine.  Try it ...

mx
mx

I don't know why but I don't think the sum of the [Approved Amount in USD Equivalent] is meant to get subtracted from 179 to get the criteria for [BankName_Facility] in the DLookUp.
mx,

Here's the issue:

<< then I need to lookup the FacilityAmount in tblBankFacilityAmts then subtract the SUM [Approved Amount In USD Equivalent]>>

The Sum needs to be subtracted from the DLookup result - not from the criteria (that is where your posts and mine are off).