Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set Name of Control base on the ControlSource of parent 1

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
I cannot figure out how to set the name of a label control to the name of it's parent ControlSource.

here is then code I have for setting everything.

Code:
            For Each ctl In frm.Section("Detail").Controls
            
'                Debug.Print ctl.Name, ctl.ControlSource
                
                ' Name specific controls according to their type
                ' making sure the control has not already been named
                Select Case ctl.ControlType
                    Case acTextBox
'                        If Left(ctl.Name, 3) = "txt" Then
                            Debug.Print "Renaming " & ctl.Name & _
                            " to " & ctl.ControlSource
'                            ctl.Name = "txt" & ctl.ControlSource
                            ctl.Name = ctl.ControlSource
'                        End If
                    Case acComboBox
'                        If Left(ctl.Name, 3) = "cbo" Then
                            Debug.Print "Renaming " & ctl.Name & _
                            " to " & ctl.ControlSource
'                            ctl.Name = "cbo" & ctl.ControlSource
                            ctl.Name = ctl.ControlSource
'                        End If
                    Case acListBox
'                        If Left(ctl.Name, 3) = "lst" Then
                            Debug.Print "Renaming " & ctl.Name & _
                            " to " & ctl.ControlSource
'                            ctl.Name = "lst" & ctl.ControlSource
                            ctl.Name = ctl.ControlSource
'                        End If
                    Case acCheckBox
'                        If Left(ctl.Name, 3) = "chk" Then
                            Debug.Print "Renaming " & ctl.Name & _
                            " to " & ctl.ControlSource
'                            ctl.Name = "chk" & ctl.ControlSource
                            ctl.Name = ctl.ControlSource
'                        End If
                    Case acLabel
                        Set ctlLabel = ctl
                            If Left(ctl.Name, 3) = "lbl" Then
                                Debug.Print "Renaming " & ctl.Name & _
                                " to " & "lbl_" & ctl.ControlSource
                                ctl.Name = "lbl_" & ctl.ControlSource
                            End If
                End Select
            Next ctl

Thanks

John Fuhrman
 
There is no such thing as a bound label so it cannot have a control source.
 
You can use the parent property if the label is linked. If you broke the link then it will return the form. You can go the other way as well. Example

ctl.Name = "txt" & ctl.ControlSource
ctl.controls(0).name = "lbl" & ctl.controlsource

Again still need to make sure there is a linked label.
 
MajP

That did it!!

ctl.controls(0).name = "lbl" & ctl.controlsource

Now just a little cleanup on the unattached labels.

Thanks

John Fuhrman
 
If that works, the parent property should have also worked. Why not the parent property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top