CallCalled Class Module

CallCalled Class Module

I will be adding information about my “CallCalled” Class Module here, as it becomes available. The most recent example of it is on Access World Forums here:-

VBA to reuse data entry popup form

This pair of functions derived from ones in the Class Module CallCalled.

I have converted them so that they work inside a Forms Code Module.

At the bottom you can see the code for a command button that will run the code and return the contents of the label attached to a text box. If your text box does not have a label, then it will return an empty string.

To recap:- The command button is called:- “btnTest”

The text box the code extracts the label caption from is called:- “txtTextBoxOnYourForm”

Private Function fHasLabel(strCtrlName As String) As Boolean
'This function Returns True if the control "strCtrlName" entered has an associated label.
'Used in "fGetLabel"

Dim Ctrl As Control

    For Each Ctrl In Me.Controls
      If Ctrl.ControlType = acLabel Then
          If Ctrl.Parent.Name = strCtrlName Then fHasLabel = True
       End If
    Next
      
End Function      'fHasLabel

Private Function fGetLabel(oCtrl As Control) As String
'Extract the caption from the passed in Control - (It's label...)

        If fHasLabel(oCtrl.Name) Then
            fGetLabel = oCtrl.Controls(0).Caption
        Else
            fGetLabel = ""
        End If

End Function      'fGetLabel

Private Sub btnTest_Click()
'Call it from a Command Button - Like This...
        MsgBox " >>> " & fGetLabel(Me.txtTextBoxOnYourForm)
End Sub