之前的函数不适合你这种子窗体再套子窗体的情况,需要将函数改一下
Public Function CheckChildChildRequired(mainForm As String, childForm As String, childchildForm As String, RequiredList As String) As Boolean
On Error GoTo ErrorHandler
Dim arr As Variant
Dim i As Integer
Dim sLabName As String
If IsNull(RequiredList) Then Exit Function
With Forms(mainForm)(childForm)(childchildForm).Form.Recordset
If .RecordCount > 0 Then .MoveFirst
Do Until .EOF
If InStr(RequiredList, "|") > 0 Then '如果有多个子窗体控件名称
arr = Split(RequiredList, "|")
For i = 0 To UBound(arr)
'MsgBox arr(i)
If IsNull(Forms(mainForm)(childForm)(childchildForm).Form!(arr(i)).Value) Then '通过子窗体上控件名称判断控件值
MsgBox "子窗体【" & arr(i) & "】是必填项,不能为空!", vbExclamation, "提示"
Exit Function
End If
Next i
Else
If IsNull(Forms(mainForm)(childForm)(childchildForm).Form!(RequiredList).Value) Then '通过子窗体上控件名称判断控件值
MsgBox "子窗体【" & arr(i) & "】是必填项,不能为空!", vbExclamation, "提示"
Exit Function
End If
End If
.MoveNext
Loop
End With
CheckChildChildRequired = True
ExitHere:
Exit Function
ErrorHandler:
MsgBox Err.Description, vbInformation, "错误提示"
Resume ExitHere
End Function
引用方式改为:
If Not CheckChildChildRequired("主窗体","Child36","frmSub", "发票号码|含税金额|无税金额|税率|凭证号") Then
Exit Sub
End If