[AccessD] Framework Discussion - Disconnected labels

John W. Colby jwcolby at colbyconsulting.com
Sat Mar 20 21:35:34 CST 2004


BTW it is possible to add controls to a control's control collection.  Thus
you can "TELL" a control in a continuous form that a label in the form's
header belongs to it.  I add a function to the class which assigns a label
out on the form to that control:

'
'Connects a label to a combo - used for continuous forms where the label is
in the header etc.
'
Function ConnectLabel(llbl As Label)
On Error GoTo Err_ConnectLabel
    Set mlbl = llbl
Exit_ConnectLabel:
Exit Function
Err_ConnectLabel:
        MsgBox Err.Description, , "Error in Function
dclsCtlTextBox.ConnectLabel"
        Resume Exit_ConnectLabel
    Resume 0    '.FOR TROUBLESHOOTING
End Function

Then, strictly for demo purposes I set and reset the label's backcolor in
the text boxes OnEnter and OnExit:

'
'These are the event stubs for the control's OnEnter and OnExit events
'
Private Sub mtxt_Enter()
    mlngBackColorOrig = mtxt.BackColor  'When we enter the text box, save
the original back color
    mtxt.BackColor = mclngBackColor     'Set the back color to our favorite
color
    mlbl.BackColor = 16744448
    mlbl.BackStyle = 1

End Sub

Private Sub mtxt_Exit(Cancel As Integer)
    mtxt.BackColor = mlngBackColorOrig  'When we exit the control, set the
back color back to the original color
    mlbl.BackStyle = 0
End Sub

In the form's Open event, after initializing the framework I call this
method and pass in a lable:

Public fdclsFrm As dclsFrm

Private Sub Form_Open(Cancel As Integer)
    Set fdclsFrm = New dclsFrm
    fdclsFrm.Init Me, Me
    With fdclsFrm.colClasses
        .item("txtCode").ConnectLabel lblCode
        .item("txtName").ConnectLabel lblName
    End With
End Sub

To see this functionality open the lfrmState and tab through the two
columns.  Again, this isn't particularly useful in this instance but it
might be a helpful indicator of cursor movement or state of a control and
again demonstrates that a disconnected label can be added to a control's
control class.

John W. Colby
www.ColbyConsulting.com





More information about the AccessD mailing list