这是我的功能:
Public Function checkIfNoll(tbl As DAO.Recordset, field As AccessObject, variable As Variant)
If IsNull(tbl!field) Then
variable = 0
Else
variable = tbl!field
End If
End Function
我有一个sql语句:
Set tblHLstrat = Nothing
sqlString2 = "SELECT [MR_PL] as mrPL, [Daily_Return_%] as mrDailyReturn, [MR_Comm] as mrComm & _
FROM tblNav_Calc WHERE tblNav_Calc.[Nav Date] = #" & tradeDate & "#"
Set tblHLstrat = db.OpenRecordset(sqlString2)
我想提供我的vba代码:
variable = checkIfNoll(tblHLstrat,mrPL(在SQL中选择的每个字段,将一遍又一遍地调用函数),变量)
我无法将表名和相应的字段名称连接为我的函数变量。如果有人可以帮助我那会很棒。
本质上,函数检查以确保字段(1,2,3,... n)不为空。如果为null,则变量(n)将设置为0.如果它不为null,则variable(n)将等于字段值。
谢谢!
答案 0 :(得分:0)
Nz(variable,valueIfNull)
您的查询将如下所示:
"SELECT [MR_PL] as mrPL, [Daily_Return_%] as mrDailyReturn, [MR_Comm] as mrComm & _
FROM tblNav_Calc
WHERE tblNav_Calc.[Nav Date] = #" & Nz(tradeDate, 0) & "#"