John W. Colby
jcolby at colbyconsulting.com
Tue Feb 18 11:54:00 CST 2003
Actually you can find the label for any given control by iterating that control's Control collection. Every control has a controls collection, and for many of the controls from Access, the label is the only control in that collection. Other controls like option groups can have many controls in it's controls collection. The following demonstrates: '.Comments : '.Parameters: '.Sets : '.Returns : '.Created by: John W. Colby '.Created : 6/17/02 11:22:19 AM ' 'Finds the label that "belongs to" any given control. ' Function CtlLbl(ctlFindLbl As Control) As Label On Error GoTo Err_CtlLbl Dim ctl As Control For Each ctl In ctlFindLbl.Controls If ctl.ControlType = acLabel Then Set CtlLbl = ctl End If Next ctl Exit_CtlLbl: Exit Function Err_CtlLbl: Select Case err Case 0 '.insert Errors you wish to ignore here Resume Next Case Else '.All other errors will trap Beep MsgBox err.Description, , "Error in Function Utils.CtlLbl" Resume Exit_CtlLbl End Select Resume 0 '.FOR TROUBLESHOOTING End Function Of course it returns a null if the control has no label. I use this code in my control classes to just routinely find and set a pointer to the label associated with a control. This allows me to do things like change the label background color as the control gets the focus etc. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-admin at databaseadvisors.com [mailto:accessd-admin at databaseadvisors.com]On Behalf Of Heenan, Lambert Sent: Tuesday, February 18, 2003 12:23 PM To: 'accessd at databaseadvisors.com' Subject: RE: [AccessD] need ideas Whether you use a class with WithEvents, or just a simple Sub that you call in the option group's On_Click event, here's an example of the basic logic that you could use to do the color changing... Sub formatOpGroup(opGrp As OptionGroup, sCaption As String) Dim c As Control For Each c In opGrp.Controls If TypeOf c Is Label Then If c.Caption = sCaption Then c.ForeColor = IIf(sCaption = "Yes", RGB(0, 255, 0), RGB(255, 0, 0)) Else c.ForeColor = RGB(0, 0, 0) End If End If Next c End Sub Lambert ---------------------------------------------------- Is email taking over your day? Manage your time with eMailBoss. Try it free! http://www.eMailBoss.com -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 2888 bytes Desc: not available URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030218/6fead505/attachment-0002.bin>