【问题标题】:How to get label text from control?如何从控件中获取标签文本?
【发布时间】:2015-05-26 22:04:42
【问题描述】:

在我的 Access 表单上,我有一个编辑控件和一个组合框。每个都有一个附在表单上的标签。

在代码中,如何获取每个控件的标签文本?我想使用标签的文本生成一个 msgbox。

我正在考虑做这样的事情[顺便说一句,你不能这样做]?

If IsNull(Me.EditControl) Then
   msgbox "My label's text is: " & me.EditControl.Label.text
Elseif IsNull(Me.ComboboxControl) Then
    msgbox "My label's text is: " & me.ComboboxControl.Label.text
End If

我想在不知道标签 ID 的情况下获取标签。

I've read through this,但它似乎对我不起作用。智能感知无法识别结构。

【问题讨论】:

    标签: ms-access vba controls


    【解决方案1】:

    标签可以作为父控件的.Controls集合中的第0项引用,标签的文本是它的.Caption属性。

    If IsNull(Me.EditControl) Then
        msgbox "My label's text is: " & Me!EditControl.Controls(0).Caption
    Elseif IsNull(Me.ComboboxControl) Then
        msgbox "My label's text is: " & Me!ComboboxControl.Controls(0).Caption
    End If
    

    【讨论】:

    • 就是这样!我错过了! 部分。感谢您的快速回答!
    • 很高兴它成功了。但我不明白为什么! 是关键。我可以使用Me.MyComboNameMe!MyComboName 引用我的组合框
    • 你可以这样引用组合框,但不能引用组合框上的标签
    • 我认为发生了其他事情。 TypeName(Me.txtProj_members) 告诉我 ComboBoxMe.txtProj_members.Controls(0).Name 显示关联标签控件的 Name,然后 Me.txtProj_members.Controls(0).Caption 显示标签的 Caption 文本。
    • 您是否正在使用 Access VBA 2010 进行测试?
    猜你喜欢
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多