title: Assign control source dynamically from a different recordset
body: <p>I have the following VBA code in my access.</p>
  
  <pre><code>Dim subform As Object
  Dim formFilter As String
  
  formFilter = "..."   'a SQL statement
  
  Set subform = Me!my_subform.Form
  subform.RecordSource = formFilter
  
  subform.field1.ControlSource = "f1"
  subform.field2.ControlSource = "f2"
  subform.field3.ControlSource = "f3"
  
  Dim db As Database
  Dim rs As Recordset
  
  Set db = CurrentDb
  Set rs = db.OpenRecordset("SELECT TOP 1 f4 FROM my_table " _
                             &amp; "WHERE tableF1= '" &amp; [f1] &amp; "' AND tableF2 = '" &amp; [f2] &amp; "' " _
                             &amp; "ORDER BY tableF5 DESC")
  subform.field4.ControlSource = rs(0)
  </code></pre>
  
  <p>I have first bound my first 3 fields in subform to the fields of my record source. Then I need to bind the 4th field to a different recordset. This recordset has to refer to the first 2 fields of my subform.</p>
  
  <p>However, I got a run-time error 2465. Access is not able to refer to the field [f1] and [f2] of my OpenRecordSet statement.</p>
  
  <p>How should I fix this?</p>
  
  <p>I use this form in a datasheet view. So I need to refer to not a single value of field1 and field2, but the entire columns of records have to be linked.</p>
  
  <p>Thanks a lot.</p>