访问检查空白、空或空字段
Access Check for Blank, Null or Empty Fields
我有一个表格,上面有几十个字段。
这些字段是文本框和组合框的组合。我试图找出一个单一的按钮解决方案来检查 empty/blank/null 字段。
如果发现空白,我希望它显示一个表格;如果找到 none,我希望它关闭当前表单。
我的代码如下。
它成功地遍历所有字段并在找到 blank/empty/null 字段时显示一个表单,但我无法弄清楚如果(且仅当)没有 blank/empty/null 表单上的字段。
Private Sub Command146_Click()
Dim ctl As Control
With Me
For Each ctl In .Controls
If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
If Len(ctl.Value & "") = 0 Then
DoCmd.OpenForm "PopMissingData"
Exit For
End If ' Value
End If ' ControlType
Next
End With
End Sub
只需检查Control对象是否有"run out":
Private Sub Command146_Click()
Dim ctl As Control
With Me
For Each ctl In .Controls
If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
If Len(ctl.Value & "") = 0 Then
Exit For
End If ' Value
End If ' ControlType
Next
End With
If ctl Is Nothing Then
' All controls validated.
DoCmd.Close acForm, Me.Name
Else
' Open the other form.
' ctl will hold the non-validated control.
DoCmd.OpenForm "PopMissingData"
End If
End Sub
我有一个表格,上面有几十个字段。
这些字段是文本框和组合框的组合。我试图找出一个单一的按钮解决方案来检查 empty/blank/null 字段。
如果发现空白,我希望它显示一个表格;如果找到 none,我希望它关闭当前表单。
我的代码如下。
它成功地遍历所有字段并在找到 blank/empty/null 字段时显示一个表单,但我无法弄清楚如果(且仅当)没有 blank/empty/null 表单上的字段。
Private Sub Command146_Click()
Dim ctl As Control
With Me
For Each ctl In .Controls
If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
If Len(ctl.Value & "") = 0 Then
DoCmd.OpenForm "PopMissingData"
Exit For
End If ' Value
End If ' ControlType
Next
End With
End Sub
只需检查Control对象是否有"run out":
Private Sub Command146_Click()
Dim ctl As Control
With Me
For Each ctl In .Controls
If ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
If Len(ctl.Value & "") = 0 Then
Exit For
End If ' Value
End If ' ControlType
Next
End With
If ctl Is Nothing Then
' All controls validated.
DoCmd.Close acForm, Me.Name
Else
' Open the other form.
' ctl will hold the non-validated control.
DoCmd.OpenForm "PopMissingData"
End If
End Sub