views:

28

answers:

1

Hi there,

As the title suggests, I'm trying to get the caption of the associated label for form controls eg:

Dim ctl As Control
Dim errMess As String
errMess = ""
For Each ctl In frm
    With ctl
            If (ctl.Tag = "*") Then
        errMess = errMess & ctl.Caption & vbNewLine        
            End If
        End If
   End With
Next ctl 

Obviously "ctl.Caption" doesn't work, I'm just not sure how to reference this.

Any help appreciated.

Cheers

Noel

A: 

Found out the answer is to use ctl.Controls.Item(0).Caption

Dim ctl As Control
Dim errMess As String
errMess = ""
For Each ctl In frm
    With ctl
            If (ctl.Tag = "*") Then
        errMess = errMess & ctl.Controls.Item(0).Caption & vbNewLine        
            End If
        End If
   End With
Next ctl
glinch
This will work only if the label is attached to the control. Also note that some control types, like an Option Group, have more than one control, and theoretically, .Controls(0) might be something other than the option group's label. And, of course, you can use ctl.Controls(0).Caption with no need for the Item().
David-W-Fenton
Thanks for the advice David, this is something that I would have overlooked completely.
glinch