Consulting

Results 1 to 2 of 2

Thread: Dynamically adding and positioning check boxes to wrap inside frame

  1. #1

    Dynamically adding and positioning check boxes to wrap inside frame

    PLEASE HELP!! I have been struggling with positioning my check boxes inside a frame.
    I have over 20 check boxes. I'm dynamically add them just fine. My problem comes when the number of checkboxes added is more than 10. After the 10th checkbox I'm unable to see the others. I know the problem is the position and I've applied code to handle when it is more than 5 for the 1st 10. But I need it to continue checking for after every 5. For example, I need 4 rows of checkboxes.. My code is below, which gives me 2 rows.

    i = 1
    c = 1
    
    For each m In mailclass
            Set chex  = me.fr_mc.controls.add("forms.checkbox.1", m)
            With chex
                       .caption  = m
                       . Value = m
                       .width = 450
                       .height = 24
                       
                       If c >5 then
                           L = 8
                           T = 20
                       Else
                          L = 0
                          T = 0
                      End If
    
                    .Left = 35 * (c - L - 1)
                    .Top = 0 + T
    
                     c = c + 1
    
                     i =  i + 1
    
             End With
    Next
    I can't figure out how to loop after the 10th check box is added.
    Any help would be greatly appreciated as I've been at this for the past 2 weeks.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
        i = 1
        c = 1
        T = -20    'adjust to set staring position as required
        
        For Each m In mailclass
        
            Set chex = Me.fr_mc.Controls.Add("forms.checkbox.1", m)
            
            With chex
            
                .Caption = m
                .Value = m
                .Width = 450
                .Height = 24
               
                If c Mod 5 = 1 Then
            
                    L = 5    'adjust to set staring position as required
                    T = T + 20
                Else
                
                    L = L + 35
                End If
    
                .Left = L
                .Top = T
    
                c = c + 1
                i = i + 1
            End With
        Next
    Last edited by Bob Phillips; 07-18-2019 at 05:57 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •