Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    How to loop through a label collection

    Just discovered something I don't know how to do........

    I have a popup form with many label controls. I need to prefix the caption of all of them with a special character. E.g., ("lbl" & "*").caption = strChar & " - " & ("lbl" & "*").caption



    What's the code structure for looping through the collection of label controls? (The special character is a "bullet" so as to make the labels appear like a bulleted list.)

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, something like...

    Note, UNTESTED and you will need to slightly modify.

    Code:
    Dim LabelNumber As Long
    LabelNumber = 1
    
    Do Until LabelNumber > 9
         Me("lbl" & LabelNumber & "Label").Caption = "YourCaptionHere"
         LabelNumber = LabelNumber + 1
    Loop
    
    If LabelNumber > 9 Then'Change the 9 to the number of labels you end up with
         LabelNumber = 1
    End If

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Perhaps something like:
    Code:
    Dim ctl As ControlFor Each ctl In Me.Controls
            If ctl.ControlType = acLabel Then
                ctl.Caption = "*" & ctl.Caption
            End If
    Next ctl
    Set ctl = Nothing
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Bob, that's exactly what I was looking for.
    Bill

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Only problem may be that it loops through labels in header and footer sections as well.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    Only problem may be that it loops through labels in header and footer sections as well.
    you can get over that by referencing the section e.g.

    each ctrl in me.detail.controls

    or

    each ctrl in me.section(0).controls

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

Similar Threads

  1. Replies: 6
    Last Post: 10-10-2017, 03:01 AM
  2. Replies: 2
    Last Post: 03-07-2017, 02:42 AM
  3. Forms collection vs. AllForms collection
    By Access_Novice in forum Programming
    Replies: 1
    Last Post: 01-03-2016, 12:30 AM
  4. Replies: 1
    Last Post: 04-25-2014, 11:41 AM
  5. Replies: 3
    Last Post: 11-16-2012, 10:15 AM

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