"Rab" <sa***************@arvatoservices.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
hi
i need to programmatically change the caption of a label that is linked
to another control (i.e. textbox, combobox). it's for a generic
function where i only know the textbox/combobox name but not the name
of the label that is linked to the textbox/combobox.
example sub:
public sub ReSetCaption()
dim ctl as Control
for each ctl in Me.Controls
if Typeof ctl is TextBox or TypeOf ctl is ComboBox then
'
'write code to set the caption of the linked label to ""
'
end if
next
End Sub
is there anyway this can be accomplished?
TIA
Rab
I would loop through all the controls and if the control is a label then see
what its parent is - i.e. what it's attached to. If you have an un-attached
label then its parent will be the form. The sub below is an example, which
could be called within any form with: SetLabelCaptions Me
Public Sub SetLabelCaptions(MyForm As Form)
On Error GoTo Err_Handler
Dim ctl As Control
For Each ctl In MyForm.Controls
With ctl
If .ControlType = acLabel Then
If .Parent.Name <> MyForm.Name Then
Select Case .Parent.ControlType
Case acTextBox
.Caption = "TB~" & .Parent.ControlSource
Case acComboBox
.Caption = "CB~" & .Parent.ControlSource
Case acCheckBox
.Caption = "CH" & .Parent.ControlSource
End Select
End If
End If
End With
Next ctl
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub