[AccessD] Re: A2K: Get Control's Label Name

Dan Waters dwaters at usinternet.com
Fri Jun 11 08:46:15 CDT 2004


Darren,

 

Yes!  

 

It turns out that textboxes and comboboxes have their own controls
collection which of course includes the label.

 

The code below is explained in ADH for AXP, page 331 Developers book.  This
works for A2000 and up.

 

 

Private Sub LabelExample()

On Error GoTo EH

 

    Dim stgTextComboBoxName As String

    Dim stgLabelName As String

    Dim stgLabelCaption As String

    Dim ctl As Control

    

    For Each ctl In Me.Controls

        stgTextComboBoxName = ctl.Name

        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then

            stgLabelCaption = ctl.Controls(0).Caption

            stgLabelName = ctl.Controls(0).Name

            MsgBox "The Text or ComboBox name is: " & stgTextComboBoxName _

                & vbCrLf & vbCrLf _

                & "The Label name is: " & stgLabelName _

                & vbCrLf & vbCrLf _

                & "The Label caption is: " & stgLabelCaption

        End If

    Next

    

    Exit Sub

    

EH:

 

End Sub

 

 

Best of Luck!

Dan Waters

 




More information about the AccessD mailing list