473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

accessing label linked to a control

Rab
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

Nov 13 '05 #1
7 4488
"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


Nov 13 '05 #2
Rab
thanks for the solution, justin. however, is there anyway i can access
the child control (a label in this case) through the parent instead of
vice versa?

Nov 13 '05 #3
"Rab" <sa***************@arvatoservices.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
thanks for the solution, justin. however, is there anyway i can access
the child control (a label in this case) through the parent instead of
vice versa?

I can't think of one. Is there something the suggested approach won't do?
I would have thought it would suit your needs perfectly.
Nov 13 '05 #4
Rab
it will take care of this function, but in another function, all i want
to pass is the name of a textbox control and based on its contents, the
associated label caption needs to be changed.

Nov 13 '05 #5
Rab wrote:
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.


An attached label is always the first item in the Controls collection of the
parent control.

Me.TextBoxName.Controls(0)

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #6

"Rab" <sa***************@arvatoservices.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
it will take care of this function, but in another function, all i want
to pass is the name of a textbox control and based on its contents, the
associated label caption needs to be changed.


For a single textbox, you could have the sub below. Note the error handling
as not all texboxes will have attached labels.

Public Sub SetCaption(txtBox As TextBox, strCaption As String)

On Error GoTo Err_Handler

txtBox.Controls(0).Caption = strCaption

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Nov 13 '05 #7
Rab
u guys are amazing!

thanks

Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Maidment | last post by:
Hi, I am a bit green when it comes to .net development so please excuse me if this question is obvious or has been asked before... I am trying to programmatically access a label control...
4
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
4
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.