Reputation: 6371
On my Access form I have an edit control and a combobox. Each has a label that is attached to it on the form.
In the code, how can I fetch the text of the label for each control? I want to produce a msgbox using the label's text.
I am thinking to do something like this [you can't do this, by the way]?
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
I would like to fetch the label without having to know the label's ID.
I've read through this, but it doesn't seem to work for me. The intellisense doesn't recognize the construction.
Upvotes: 1
Views: 3763
Reputation: 97101
The label can be referenced as item 0 in the parent control's .Controls
collection, and the label's text is its .Caption
property.
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
Upvotes: 2