jwcolby
jwcolby at colbyconsulting.com
Fri Jun 11 06:38:41 CDT 2004
Now see, if you'd been paying attention to the framework discussion...
The label is not a property, but a control in each control's "control
collection". In order to find the control, you iterate through the controls
collection for the given control looking for a control with the controltype
acLabel. The following function will find that control and return a pointer
to it. You can then use it directly:
CtlLbl(txtLastName).Caption = "Last Name"
Or you can assign the pointer to a local variable:
Dim lbl as Label
set lbl = CtlLbl(txtLastName)
lbl.Caption="Last Name"
By assigning it to a variable you can quickly and easily come back and
change the background color, font, bold, italic etc.
I have a label variable in each of my control classes, which I populate as
soon as the control is passed in. Thus each control class has access to
it's label (if any).
'
'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
Exit For
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
John W. Colby
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Darren DICK
Sent: Friday, June 11, 2004 12:17 AM
To: AccessD List
Subject: [AccessD] A2K: Get Control's Label Name
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