jwcolby
jwcolby at colbyconsulting.com
Fri Jun 11 09:58:32 CDT 2004
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