在vba访问中获取checkBox的值?

时间:2014-02-21 16:50:42

标签: ms-access access-vba

好的,所以我在Access表单中有几个“复选框”。我所要做的就是获取复选框的Checked Value。

通过做Me.Check271.Value它返回0或-1。但

我希望获得已检查CheckBox的标签

在下图中我想要msgbox检查的值:

我正在尝试的是:

MsgBox“Me.Check271.Parent”

enter image description here

非常感谢

1 个答案:

答案 0 :(得分:3)

简而言之,以下内容将起作用:

Check271.Controls.Item(0).Caption

详细版本:TextBoxes,ComboBoxes,ListBoxes,CheckBoxes在其控件集合中最多有1个项目(附加标签),但如果没有附加标签,它们甚至不会有,所以.Controls( 0)会抛出错误。

以下内容将显示“已检查”的复选框

Dim ctl         As Control
Dim blnChecked  As Boolean
Dim strChecked  As String

For Each ctl In Me.Section("Detail").Controls
    If ctl.ControlType = acCheckBox Then
        If ctl.Enabled = True Then
            Debug.Print ctl.Name & vbTab & ctl.Value
            If ctl.Value = vbTrue Then
                blnChecked = True
                strChecked = strChecked & ctl.Name & "; "
            End If
        End If
    End If
Next ctl
If blnChecked = True Then
    MsgBox "The following CheckBoxes were checked: " & strChecked, vbOKOnly, "Checked Boxes"
End If
相关问题