title: Use Access VBA to change the record source for a form
body: <p>I am creating a search form and I am unable to see the search results in the subform.
  The query runs fine, I have set the subforms record source to the query. I donot get any errors. When I click the search button the query runs and it shows the number of rows in the record selector at the bottom of the subform, but i cannot see the rows.</p>
  
  <p>Here is my code for the OnClick event of the button:</p>
  
  <pre><code>Private Sub cmdSearch_Click()
  
  Dim tableName As String
  Dim colName As String
  Dim keyword As String
  Dim strSQL As String
  
  tableName = Me.cmbTableNames.Value
  colName = Me.cmbColumnNames.Value
  keyword = Me.txtKeyword.Value
  strSQL = "Select * from [" &amp; [tableName] &amp; "] where [" &amp; [colName] &amp; "] like '*" &amp;  [keyword] &amp; "*';"
  Debug.Print strSQL
  Me.searchResultsForm.Visible = True
  
  Forms![F_SearchForm]![searchResultsForm].Form.RecordSource = "Select * from [" &amp;   [tableName] &amp; "] where [" &amp; [colName] &amp; "] like '*" &amp; [keyword] &amp; "*';"
  Forms![F_SearchForm]![searchResultsForm].Form.Requery
  End Sub
  </code></pre>
  
  <p>Can someone tell me what I am doing wrong.</p>
  
  <p>Thank You</p>
  
  <p>This is what shows up in the Immediate Window for Debug.Print</p>
  
  <pre><code>Select * from [dbo_Internal Contacts] where [First Name] like '*Amy*';
  </code></pre>
  
  <p>My Form looks like this in the form view: </p>
  
  <p><img src="https://i.stack.imgur.com/OAyLH.png" alt="enter image description here"></p>
  
  <p>I have added some text boxes to my subform (around 35). Now if I run the query my form looks like this: 
  <img src="https://i.stack.imgur.com/Chho2.png" alt="enter image description here"></p>
  
  <p>How can I link these text boxes on the subform to the columns in the recordsource using vba?</p>
  
  <p>Please help</p>