在MS Access 2010数据库中,我有一个导航子窗体,其中包含一些文本框,其值从基础查询填充,以及一个计算的文本框。我想在计算的文本框中添加一些条件逻辑。
两个填充的文本框是ClientNumber和DOB。在表达式构建器中,计算的文本框是Age,目前计算如下:
=DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))
我想将Age计算更改为类似下面的伪代码:
=IiF(
ClientNumber IN qryActiveClients,
DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd")) ,
"NA"
)
有人可以告诉我如何更改此伪代码,使其成为实际所需任务的实际工作代码吗?
作为参考,qryActiveClients如下:
SELECT DISTINCT
ActiveCustomers.FirstName,
ActiveCustomers.LastName,
tblClientAddress.HomePhone,
ActiveCustomers.ClientNumber
FROM
(
SELECT
Clients.ClientNumber,
Clients.FirstName,
Clients.LastName,
(
SELECT COUNT(ReferralDate) FROM IntakeTable
WHERE Clients.ClientNumber = IntakeTable.ClientNumber
AND Len(ReferralDate & '') > 0
) AS IntakeCount,
(
SELECT COUNT(ExitDate) FROM ExitTable
WHERE Clients.ClientNumber = ExitTable.ClientNumber
AND Len(ExitDate & '') > 0
) AS ExitCount FROM Clients
) AS ActiveCustomers
INNER JOIN tblClientAddress
ON ActiveCustomers.ClientNumber = tblClientAddress.ClientNumber
WHERE (((ActiveCustomers.IntakeCount)>[ExitCount]) AND ((tblClientAddress.CurrentResidence)=True));
请注意,qryActiveClients与填充其他控件的查询不同。
答案 0 :(得分:2)
我相信你正在寻找这样的东西:
=IIf(
DCount("*", "qryActiveClients", "ClientNumber=" & [ClientNumber]) > 0,
DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd")),
"NA"
)