[AccessD] A2K: Get Control's Label Name

Heenan, Lambert Lambert.Heenan at AIG.com
Fri Jun 11 09:37:42 CDT 2004


It's been a few years since I tested it, but I think so. Let's see...

test, test, test

... Yup!

I created a from with a textbox a combo a list box and an option group frame
and a command button . Then run this code behind the button

Private Sub Command6_Click()
    Dim c As Control
    Dim msg As String
    For Each c In Me
        Select Case c.ControlType
        Case acLabel
            msg = "Control " & c.Name & " is a label with the caption " &
c.Caption
        Case acCommandButton
            msg = "Control " & c.Name & " is a Button with the caption " &
c.Caption
        Case Else
            msg = "Control " & c.Name & " has caption " &
Nz(c.Controls(0).Caption, "-nothing-")
            
        End Select
        MsgBox msg
    Next c
End Sub

Next delete all the labels. Then create new labels anywhere on the form, cut
them out, select a control and paste the labels onto it, thus binding them
(adding them to the Controls collection). Re-ran the code and all the
captions were reported correctly.

To be honest I don't think I've come across an control with more than one
item in it's Controls collection. If you can give me an example it should be
simple enough to test.

Lambert

> -----Original Message-----
> From:	jwcolby [SMTP:jwcolby at colbyconsulting.com]
> Sent:	Friday, June 11, 2004 10:13 AM
> To:	'Access Developers discussion and problem solving'
> Subject:	RE: [AccessD] A2K: Get Control's Label Name
> 
> Have you tested the "always the first" thing?  If I delete the label, then
> append it back in, does Access move the existing controls still in the
> collection so that the label is first?
> 
> John W. Colby 
> www.ColbyConsulting.com
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
> Sent: Friday, June 11, 2004 9:47 AM
> To: 'Access Developers discussion and problem solving'
> Cc: 'd.dick at uws.edu.au'
> Subject: RE: [AccessD] A2K: Get Control's Label Name
> 
> 
> There's a much simpler way:
> 
> If a control (any control) has a label bound to it (the label moves when
> you
> move the control) the this function does the job
> 
> Function ControlCaption(c As Control) As String
>     If c.Controls.Count = 0 Then
>        ' the control does not have a label bound to it
>        ' just return the control's data source
>         ControlCaption = Nz(c.ControlSource,"")
>     Else
> 	' The control has a label, and it's always the first
> 	' in the Control's collection for the control we're looking at
>         ControlCaption = c.Controls(0).Caption
>     End If
> End Function
> 
> No need to reference the containing form object, no need for any naming
> convention, no need to use the tag property, no need to iterate anything.
> Just go get the caption.
> 
> Lambert
> 
> > -----Original Message-----
> > From:	Darren DICK [SMTP:d.dick at uws.edu.au]
> > Sent:	Friday, June 11, 2004 2:52 AM
> > To:	Access Developers discussion and problem solving
> > Subject:	Re: [AccessD] A2K: Get Control's Label Name
> > 
> > Thanks Rocky
> > I'm gonna use a bit of each
> > 
> > Private Sub ps_SetVisibles(intListItem As Integer)
> > Dim ctl As Control
> > Dim strLabelCaption As String
> > For Each ctl In Me.Controls
> >     If Mid(ctl.Tag, 3, 1) = intListItem Then
> >         ctl.Enabled = True
> >         strLabelCaption = Me("lbl" & Mid(ctl.Name, 4, 
> > Len(ctl.Name))).Caption
> >         MsgBox strLabelCaption
> >     End If
> > Next
> > 
> > End Sub
> > 
> > 
> > ----- Original Message -----
> > From: "Rocky Smolin - Beach Access Software" <bchacc at san.rr.com>
> > To: "Access Developers discussion and problem solving"
> > <accessd at databaseadvisors.com>
> > Sent: Friday, June 11, 2004 4:31 PM
> > Subject: Re: [AccessD] A2K: Get Control's Label Name
> > 
> > 
> > > Darren:
> > > 
> > > Off the top of my head.  Don't know if this'll do but, how about:
> > > 
> > > dim txt as Control
> > > dim lbl as Control
> > > 
> > > set txt=(text box control name)
> > > set lbl="lbl" & txt.Name
> > > 
> > > Now you've got lbl as the label object and all its properties are
> > available.
> > > 
> > > HTH
> > > 
> > > Rocky Smolin
> > > Beach Access Software
> > > http://www.e-z-mrp.com
> > > 
> > > 
> > > ----- Original Message -----
> > > From: "Darren DICK" <d.dick at uws.edu.au>
> > > To: "Access Developers discussion and problem solving"
> > > <accessd at databaseadvisors.com>
> > > Sent: Thursday, June 10, 2004 11:18 PM
> > > Subject: Re: [AccessD] A2K: Get Control's Label Name
> > > 
> > > 
> > > > Thanks Bob
> > > > The naming convention I am using is different to that
> > > > We are using "lbl" and then the control name
> > > > I am not even directly referring to the 'Parent control' either. I 
> > > > am using TAGs that meet a criteria. I was hoping it was an exposed 
> > > > property of some kind
> > > >
> > > > DD
> > > >
> > > > ----- Original Message -----
> > > > From: "Bob Gajewski" <rbgajewski at adelphia.net>
> > > > To: "Access Developers discussion and problem solving"
> > > <accessd at databaseadvisors.com>
> > > > Sent: Friday, June 11, 2004 3:51 PM
> > > > Subject: RE: [AccessD] A2K: Get Control's Label Name
> > > >
> > > >
> > > > > Darren
> > > > >
> > > > > I believe that the default label name is FieldName_Label, so you 
> > > > > can
> > > always
> > > > > just append the _Label to your field names for handling (eg: if 
> > > > > the
> > > field
> > > > > name is txtMyTextBox then the label's caption should be 
> > > > > Me.txtMyTextBox_Label.caption).
> > > > >
> > > > > Regards,
> > > > >
> > > > > Bob Gajewski
> > > > >
> > > > >
> > > > > -----Original Message-----
> > > > > From: accessd-bounces at databaseadvisors.com
> > > > > [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Darren
> > DICK
> > > > > Sent: Friday, June 11, 2004 01:37
> > > > > To: Access Developers discussion and problem solving
> > > > > Subject: Re: [AccessD] A2K: Get Control's Label Name
> > > > >
> > > > >
> > > > > Yeah I do that too
> > > > > but in this case I can't because things are being done 
> > > > > differently using tags
> > > > >
> > > > > Many thanks
> > > > >
> > > > > DD
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Christopher Hawkins" <clh at christopherhawkins.com>
> > > > > To: <accessd at databaseadvisors.com>
> > > > > Sent: Friday, June 11, 2004 2:27 PM
> > > > > Subject: RE: [AccessD] A2K: Get Control's Label Name
> > > > >
> > > > >
> > > > > > I may be doing it the hard way, but I've always named my 
> > > > > > labels
> > 'lbl'
> > > > > > & ControlName.
> > > > > >
> > > > > > -C-
> > > > > >
> > > > > > ---- Original Message ----
> > > > > > From: d.dick at uws.edu.au
> > > > > > To: AccessD at databaseadvisors.com,
> > > > > > Subject: RE: [AccessD] A2K: Get Control's Label Name
> > > > > > Date: Fri, 11 Jun 2004 14:16:57 +1000
> > > > > >
> > > > > > >Hello all
> > > > > > >When I drop a control onto a form (say a text Box) The system 
> > > > > > >usually it something like Text0 or text1 etc and it
> > also
> > > > > > >creates its very own label with similar names.
> > > > > > >
> > > > > > >If I know the name of a control can I get it's label name and 
> > > > > > >or caption or any such properties?
> > > > > > >
> > > > > > >eg Me.txtMyTextBox.ChildLabel.caption
> > > > > > >
> > > > > > >Many thanks in advance
> > > > > > >
> > > > > > >Darren
> > > > > > >
> > > > > > >--
> > > > > > >_______________________________________________
> > > > > > >AccessD mailing list
> > > > > > >AccessD at databaseadvisors.com 
> > > > > > >http://databaseadvisors.com/mailman/listinfo/accessd
> > > > > > >Website: http://www.databaseadvisors.com
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > _______________________________________________
> > > > > > AccessD mailing list
> > > > > > AccessD at databaseadvisors.com 
> > > > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > > > Website: http://www.databaseadvisors.com
> > > > > --
> > > > > _______________________________________________
> > > > > AccessD mailing list
> > > > > AccessD at databaseadvisors.com 
> > > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > > Website: http://www.databaseadvisors.com
> > > > >
> > > > >
> > > > > --
> > > > > _______________________________________________
> > > > > AccessD mailing list
> > > > > AccessD at databaseadvisors.com
> > > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > > Website: http://www.databaseadvisors.com
> > > > --
> > > > _______________________________________________
> > > > AccessD mailing list
> > > > AccessD at databaseadvisors.com
> > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > Website: http://www.databaseadvisors.com
> > > 
> > > --
> > > _______________________________________________
> > > AccessD mailing list
> > > AccessD at databaseadvisors.com
> > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > Website: http://www.databaseadvisors.com
> > --
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 
> 
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list