如何绕过从绑定表单收到的null

时间:2016-08-11 12:09:00

标签: vba ms-access

我的父表单带有按钮。按钮的事件是VBA代码,它调用函数。该函数需要从子表单接收一些字段。

按钮事件:

Private Sub btn_Click()
    Call myFunction(childForm!contactId, childForm!companyId, _
    childForm!lastName, childForm!firstName, childForm!email) 
End Sub

问题是,有时某些或所有字段都为空,然后我收到错误消息。

myFunction的:

Public Sub myFunction(ByVal contactId As Integer, ByVal companyId As Integer, _ 
ByVal lastName As String, ByVal firstName As String, ByVal email As String)

除了用条件和变量编写一长段代码之外,还有办法解决这个问题吗?

if isnull(childForm!contactId) then
    strContactId = ""
End If
'...etc...

1 个答案:

答案 0 :(得分:2)

您可以使用Nz Function

    Private Sub btn_Click()
        Call myFunction(Nz(childForm!contactId,0), Nz(childForm!companyId,0), _
        Nz(childForm!lastName,""), Nz(childForm!firstName,""), Nz(childForm!mail,"")) 
    End Sub