带有相应文本字段的复选框的验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有相应文本字段的复选框的验证相关的知识,希望对你有一定的参考价值。

  1. Private Sub chkOther_BeforeUpdate(Cancel As Integer)
  2.  
  3. ' Validation for check box with a corresponding text field.
  4. ' When users check chkOther, they are encouraged to specify in txtOther what they mean.
  5. ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
  6. ' tells them the data in txtOther will be deleted. This prevents orphaned data
  7. ' being stored in txtOther when chkOther isn't checked.
  8.  
  9. If Not IsNull(Me.txtOther) Then ' If txtOther has data
  10. If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then ' and the user unchecks chkOther, ask the user to confirm the change
  11. If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
  12. Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then
  13. ' If the user clicks 'Yes'
  14. Me.txtOther = Null ' delete the data in txtOther
  15. Else ' Otherwise, if the user doesn't click 'Yes'
  16. Cancel = True ' don't go through with the change (i.e., cancel the update),
  17. Me.chkOther.Undo ' restore the value of chkOther to the original answer (i.e., checked)
  18. Exit Sub ' and leave this routine
  19. End If
  20. End If
  21. End If
  22.  
  23. 'Check the final value in chkOther to determine whether to enable or disable txtOther.
  24. 'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
  25. 'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).
  26.  
  27. Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
  28.  
  29. End Sub

以上是关于带有相应文本字段的复选框的验证的主要内容,如果未能解决你的问题,请参考以下文章

创建带有文本字段的 Material Ui 复选框

根据复选框条件验证输入文本字段(最大值和最小值)

将复选框与相应的输入字段分组

当当前输入等于数组内的值时,Laravel 验证 required_if(带有输入文本的复选框)

ExtJS 4.2.1 - 表单自定义字段验证

验证隐藏的多复选框/输入字段