Ms access 访问VBA-已选中表单上的所有复选框
我是访问VBA的新手,有一个表单,上面有大约30个复选框。保存表单时,我希望确保所有复选框都已勾选并设置为true。勾选框都有名称SC1、SC2……SCN是否有方法循环每个控件,并查看是否已将其设置为true? 这是我尝试过的,但它似乎没有读到提示框-Ms access 访问VBA-已选中表单上的所有复选框,ms-access,vba,Ms Access,Vba,我是访问VBA的新手,有一个表单,上面有大约30个复选框。保存表单时,我希望确保所有复选框都已勾选并设置为true。勾选框都有名称SC1、SC2……SCN是否有方法循环每个控件,并查看是否已将其设置为true? 这是我尝试过的,但它似乎没有读到提示框- Private Sub Validate_Data(rstTop) Dim n As Integer Dim count As Integer count = 0 For n = 1 To rstTop If Form.Controls
Private Sub Validate_Data(rstTop)
Dim n As Integer
Dim count As Integer
count = 0
For n = 1 To rstTop
If Form.Controls("SC" & n).Value = False Then
count = count + 1
End If
Next
If count <> 0 Then
MsgBox "Not all Questions have been ticked, please tick and add comments", vbInformation, _
"More information Required"
Else
End If
End Sub
试试看,它对我有用
Option Compare Database
Option Explicit
Private Function Validate_Data() As Boolean
Dim ctl As Control
Validate_Data = True 'initialize
For Each ctl In Me.Form.Controls
If ctl.ControlType = acCheckBox Then
If (ctl.Name Like "SC*") And (ctl.Value = False) Then
MsgBox "Not all Questions have been ticked, please tick and add comments", vbInformation, _
"More information Required"
Validate_Data = False 'something isnt checked
Exit Function
End If
End If
Next ctl
End Function
Private Sub cmdGo_Click()
Validate_Data
End Sub