Don't use Dlookup, use a simple join. Assuming roughly this structure:
Code:
tblClients
ClientID PK
ModelID FK to tblModels
tblModels
ModelID PK
ModelName text
tblCategories
CatID PK
CatDesc Text
CatNotes Memo
tblModelTargets
MTKey Autokey
ModelID FK to tblModels
CatID FK to tblCategories
TargPercent Currency (to get 4 digits)
And assuming that your existing query gets you something like this:
Code:
qryPortfolios
ClientID FK to tblClients
CatID FK to tblCategories
CatAmount Currency
TotAmount Currency
CatPercent Currency (to get 4 digits)
You can use this kind of join, which will give you the desired percentage for each:
Code:
SELECT
Q1.ClientID,
Q1.CatID,
Q1.CatAmount,
Q1.TotAmount,
Q1.CatPercent,
TM.TargPercent
FROM
((qryPortfolios AS Q1
INNER JOIN tblClients AS TC
ON TC.ClientID = Q1.ClientID)
INNER JOIN tblModelTargets AS TM
ON TC.ModelID = TM.ModelID
AND Q1.CatID = TM.CatID)
Hmmm. Nope. Unfortunately, using that direction for the join leaves a hole where the person has none of any given category which is required by the model.
Hmmm. Okay, go this way:
Code:
SELECT
TC.ClientID,
TM.CatID,
TM.TargPercent,
NZ(Q1.CatAmount) As CatAmount,
NZ(Q2.TotAmount) As TotAmount,
NZ(Q1.CatPercent) As CatPercent
FROM
( ( (tblClients AS TC
LEFT JOIN
(SELECT ClientID, MAX(TotAmount) AS TotAmount
FROM qryPortfolios
GROUP BY ClientID
) AS Q2
ON TC.ClientID = Q2.ClientID
)
LEFT JOIN tblModelTargets AS TM
ON TC.ModelID = TM.ModelID
)
LEFT JOIN qryPortfolios AS Q1
ON Q1.ClientID = TC.ClientID
AND Q1.CatID = TM.CatID
)