Results 1 to 8 of 8

Can a loop within a loop refer to each others controls?

Threaded View

  1. #1
    Registered User
    Join Date
    01-09-2015
    Location
    Ontario, Canada
    MS-Off Ver
    2010
    Posts
    12

    Can a loop within a loop refer to each others controls?

    Hi,
    Just as the title asks, wondering if its possible or if I have not set up the this code correctly.

    Trying to loop through 34 check boxes and check if they equal true (checked) and then at the same time loop through my 34 text boxes with some dates and additions.
    Was hoping this would work and save me a lot of typing or copying and pasting by just creating this once in a sub CheckBoxes and calling to it from the check boxes click events.

    Here is what I thought would work

    Sub Checkboxes()
        'Check box to put a date and time stamps in DateSprayed, ReEntry, and PHI text boxes on userform
    Dim i As Integer
    Dim x As Integer
    
    With Checklist
        For i = 1 To 34
            If Me.Controls("chk" & i) = True Then
                With Checklist
                    For x = 1 To 34
                        Me.Controls("txtDateSprayed" & x).Value = Now()
                        Me.Controls("txtReEntry" & x).Value = DateAdd("H", txtMaxReEntry, Me.Controls("txtDateSprayed" & x).Value)
                        Me.Controls("txtPHI" & x).Value = DateAdd("H", txtMaxPHI, Me.Controls("txtDateSprayed" & x).Value)
                    Next x
                End With
            Else
                With Checklist
                    For x = 1 To 34
                        Me.Controls("txtDateSprayed" & x).Value = ""
                        Me.Controls("txtReEntry" & x).Value = ""
                        Me.Controls("txtPHI" & x).Value = ""
                        'Format to dates and times
                        Me.Controls("txtDateSprayed" & x).Value = Format(Me.Controls("txtDateSprayed" & x).Value, "mmm-dd-yy - HH:MM")
                        Me.Controls("txtReEntry" & x).Value = Format(Me.Controls("txtReEntry" & x).Value, "mmm-dd-yy - HH:MM")
                        Me.Controls("txtPHI" & x).Value = Format(Me.Controls("txtPHI" & x).Value, "mmm-dd-yy - HH:MM")
                    Next x
                End With
            End If
        Next i
    End With
    End Sub
    Thanks to anyone who may shed some light on this.
    Last edited by frontypro4x; 01-19-2015 at 05:52 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Refer sheet name by For Each loop error
    By Jul Stev in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2014, 11:21 PM
  2. [SOLVED] refer to Textbox using a loop
    By mortphil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2013, 06:55 AM
  3. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  4. Refer checkbox by name in a loop
    By Xtender in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2006, 07:50 AM
  5. How to loop through controls on a MultiPage
    By 42N83W in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-14-2005, 08:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1