Heenan, Lambert
Lambert.Heenan at AIG.com
Fri Jun 11 11:03:45 CDT 2004
Ah yes! Of course, Frames!
So here is the newest version of my handy-dandy function
Function ControlCaption(c As Control) As String
Dim c2 As Control
If c.Controls.count = 0 Then
ControlCaption = c.ControlSource
Else
Select Case c.ControlType
Case acOptionGroup
ControlCaption = ""
' default value in case there is no label, don't want to return Null
For Each c2 In c.Controls
Select Case c2.ControlType
Case acLabel
If c2.Parent.Name = c.Name Then
ControlCaption = c2.Caption
Exit For
End If
End Select
Next c2
Case Else
ControlCaption = c.Controls(0).Caption
End Select
End If
End Function
A little longer, but is only has to loop through the controls colletion of
Frames, nothing else.
Thanks for setting me straight John.
Lambert
> -----Original Message-----
> From: jwcolby [SMTP:jwcolby at colbyconsulting.com]
> Sent: Friday, June 11, 2004 10:59 AM
> To: 'Access Developers discussion and problem solving'
> Subject: RE: [AccessD] A2K: Get Control's Label Name
>
> Frames have the check boxes in their controls collection don't they?
>
> And I just tested it, and the frame's label ends up last when deleted then
> added back in. I created a frame with three option buttons. The
> following
> code printed
>
> Option3
> Label4
> Option5
> Label6
> Option7
> Label8
> lblFra1
>
> To the debug window when run after deleting and reinserting the label.
>
> Private Sub Form_Load()
> Dim fra As Control
> Dim ctl As Control
>
> Set fra = Frame0
> For Each ctl In fra.Controls
> Debug.Print ctl.Name
> Next ctl
> End Sub
>
> The method I gave for iterating the controls collection looking for the
> control of type label should always work.
>
> 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 10:38 AM
> To: 'Access Developers discussion and problem solving'
> Subject: RE: [AccessD] A2K: Get Control's Label Name
>
>
> 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
>
>
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com