Results 1 to 8 of 8
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479

    Text box properties - debug printing

    Looking at Text Box properties the first 3 entries are




    Name
    Label Name
    Control Source


    So I try:
    Code:
    For Each ctl In Form_xxx.subFormyyyy.Controls
            If ctl.ControlType = acTextBox Then
                Debug.Print ctl.Name, ctl.ControlSource, ctl.LabelName
            End If
    Next
    This gives an error on LabelName. I can't leave in the space and ctl.[Label Name]
    doesn't work eitehr. But the space in "Control Source" can be removed and no error.
    Why not the same for label name and how can it be debug printed?
    Thanks.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    A label is a control in its own right, and apparently not a property of its textbox owner.

    Code:
        For Each ctl In Form_xxx.subFormyyyy.Controls
            Select Case ctl.ControlType
                Case acTextBox
                    Debug.Print ctl.Name, ctl.ControlSource
                Case acLabel
                    Debug.Print ctl.Name
            End Select
        Next

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If a control has an associated label, that label is an element of the control.

    Middlemarch, you've already used it in other thread discussion:

    ctl.Controls(0).Caption

    Code will error if control does not have associated label (as I noted in other thread).

    I do not see Label Name property. Must be feature added after Access2010. Even if there is now a Label Name property displayed, code likely still uses the old syntax to reference associated label.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Join Date
    Jun 2022
    Posts
    28
    Quote Originally Posted by Middlemarch View Post
    Name
    Label Name
    Control Source
    Code:
    For Each ctl In Form_xxx.subFormyyyy.Controls
            If ctl.ControlType = acTextBox Then
                Debug.Print ctl.Name, ctl.ControlSource, ctl.LabelName
            End If
    Next
    Try:

    Code:
    ctl.Properties("LabelName")

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    This is not valid code and will error

    For Each ctl In Form_xxx.subFormyyyy.Controls

    you are missing a .form

    For Each ctl In Form_xxx.subFormyyyy.form.Controls

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    CJ, I tested this code. It works with or without .Form qualifier. Related thread https://www.accessforums.net/showthread.php?t=89874
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Thank you senor that was helpful,
    I have 2 functions that use Select Case that might be improved . One is sent a label caption and returned the control name.
    The other gets the control name and returns the label caption.
    I did it this was as the Form_Form syntax was just so hard to get right.
    The Form name is frmMain and its Subform is SubDisplay

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    It works with or without .Form qualifier
    New one on me

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-07-2022, 09:24 PM
  2. Currency appears as text in vba debug
    By Gina Maylone in forum Access
    Replies: 5
    Last Post: 03-29-2018, 04:32 AM
  3. Text Box Properties restrict to 255 characters
    By Ruegen in forum Programming
    Replies: 7
    Last Post: 11-18-2014, 05:03 AM
  4. Change properties of a text box
    By GraeagleBill in forum Reports
    Replies: 5
    Last Post: 08-29-2013, 11:22 AM
  5. Replies: 5
    Last Post: 06-23-2012, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums