第一步:新建一模块,命名为:module1,将下面的函数复制到模块中:
'求和字段函数
Function ValHecheng(a As Long, b As Long, c As Long) As Long
'首先我们知道a肯定是不会为0的
'如果B为0并且C为0
If b = 0 And c = 0 Then
ValHecheng = a
End If
'如果B不为0且C为0
If b > 0 And c = 0 Then
ValHecheng = a + b
End If
'如果全部不为0
If b > 0 And c > 0 Then
ValHecheng = a + b + c
End If
End Function
'合并字段函数
Function strHecheng(a As Long, b As Long, c As Long) As String
If b = 0 And c = 0 Then
strHecheng = a
End If
If b > 0 And c = 0 Then
strHecheng = a & "+" & b
End If
If b > 0 And c > 0 Then
strHecheng = a & "+" & b & "+" & c
End If
End Function
第二步:新建一查询,应用上面的函数,详见示例。
示 例:
点击浏览该文件