title: Would like to run a query that is using a field in a table for it's criteria (would like to loop)
body: <p>I am new and have very basic knowledge of programming. </p>
  
  <p>So, I have a table that contains fields that is written in the same way as you would write a criteria for a field in queries (ex: the field would contain <code>"1234 Or 1242"</code> or some date range: <code>"Between #06/23/2019# and #06/25/2019#"</code>). I would like to run a loop that looks at each line of this table and run queries that are referencing these fields</p>
  
  <p>I've figured out the loop but for the life of me I can't figure out how to run the query with the string in the field of the referenced table as a criteria. So I left it blank.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub testPromo_Click()
  
  Dim strSQL As String
  Dim strDEPTCriteria As String
  Dim rs As DAO.Recordset
  
  strSQL = "PromoTable"
  Set rs = CurrentDb.OpenRecordset(strSQL)
  
  With rs
      If Not .BOF And Not .EOF Then
      .MoveFirst
          While (Not .EOF)
  
              DoCmd.OpenQuery "SelectedDepts"
  
              .MoveNext
          Wend
      End If
      .Close
  End With
  
  ExitSub:
      Set rs = Nothing
      Exit Sub
  
  End Sub
  </code></pre>