title: Iterating through a variant array
body: <p>I am trying, with a form, to enter a directory, a parent folder name and then select via tabs which sub-folders will feature within the parent folder using a range of checkboxes.</p>
  
  <p><img src="https://i.stack.imgur.com/iGcOY.jpg" alt="My user form"></p>
  
  <p>I can enter the drive, project name and project number which first checks if the parent folder exists and if not creates it.</p>
  
  <p>I then check if the 'Use Online' checkbox is active and if so create an array of the names of all of the other checkboxes within the 'Online' tab. It then gets tricky because I want to loop through each of the checkbox names to check whether each one is active and if so, I want to grab the 'caption' of each checkbox and use it to create a sub-folder within the parent directory (if it does not already exist).</p>
  
  <p>When I execute my current code I get 'Run-time error '424' Object required and the line </p>
  
  <pre><code>    If itm.Value = True Then
  </code></pre>
  
  <p>highlighted in yellow.</p>
  
  <p>All of the code used for the 'create folders' part of this user form can be found below:</p>
  
  <pre><code>Private Sub create_folders_button_Click()
  
  'Create a variable for the drive letter
  Dim driveLetter As String
  driveLetter = drive_list.Value
  
  'Create a variable for the project name
  Dim projectName As String
  projectName = p_name_textbox.Value
  
  'Create a variable for the project number
  Dim projectNumber As String
  projectNumber = p_number_textbox.Value
  
  'Create a variable for the constructed BasePath
  Dim BasePath As String
  
  'Create a new file system object for handling filesystem manipulation
    Set fs = CreateObject("Scripting.FileSystemObject")
  
  'Populate an array with the online subfolders
    Dim onlineSubfolders As Variant
    onlineSubfolders = Array("online_progCosts", "online_exports")
  
  'Compile the basePath
  
    BasePath = driveLetter &amp; projectName &amp; " (" &amp; projectNumber &amp; ")"
  
  'Check if the project folder already exists and if so, raise an error and exit
      If Dir(BasePath, vbDirectory) &lt;&gt; "" Then
          MsgBox BasePath &amp; " already exists", , "Error"
      Else
          'Create the project folder
          MkDir BasePath
          MsgBox "Parent folder creation complete"
  
          If online_toggle.Value = True Then
              Dim online As String
              online = "Online"
              MkDir BasePath &amp; "\" &amp; online
  
              Dim itm As Variant
              For Each itm In onlineSubfolders
                  If folder_creator_window.Controls(itm).Value = True Then
                      Dim createFolder As String
                      createFolder = folder_creator_window.Controls(itm).Caption
                      NewFolder = BasePath &amp; "\" &amp; online &amp; "\" &amp; createFolder
                      If fs.folderexists(NewFolder) Then
                          'do nothing
                      Else
                          MkDir NewFolder
                      End If
  
                  Else
                      'do nothing
                  End If
  
              Next itm
  
          Else
              MsgBox "The online folder was not created because it was not checked"
  
          End If
  
      End If
  
  End Sub
  </code></pre>