title: Linking Second Variable Iteration to First
body: <p>Hi I need some help to finalize the following code I've placed in Access.  I'm looking for suggestions in modifying the code regarding the mfile variable so that matches the file variable in how it iterates through all the Excel files in the directory.</p>
  
  <pre><code>Public Function load_data()
  'mfile is modified filename with "xl" prefix to group all imported tables 
  together
  
  Dim file, mfile As Variant    
  file = Dir(CurrentProject.Path &amp; "\")
  mfile = "xl_" &amp; Left(file, Len(file) - 5)
  
  Do Until file = ""    
      Debug.Print mfile           
      If file Like "*.xlsx" Then            
          For Each tbl In CurrentDb.TableDefs            
              If mfile = tbl.Name Then                
                  DoCmd.DeleteObject acTable, tbl.Name
                  Exit For                
              End If            
          Next tbl           
          DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, mfile, CurrentProject.Path &amp; "\" &amp; file, True           
      End If           
      file = Dir           
  Loop
  
  End Function
  </code></pre>