第一步:新建一模塊,命名為: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
第二步:新建一查詢,應用上面的函數,詳見示例。